烦恼了很久的有自适应无缓动不知如何解决,终于从茫茫网海中找出来了,赶紧分享,学习。
-----------------------------------------------------------------------------------------------------------------------------------------
AS3.0代码如下:
import com.greensock.TweenLite;//这个TweenLite类包网上很多的,可以自己下载哦,我都不多说了。
import com.greensock.easing.*;
stage.scaleMode=StageScaleMode.NO_SCALE;//放大时元件不会变形
stage.align=StageAlign.TOP_LEFT;//放大时舞台的坐标始终在窗口左上角
stage.addEventListener(Event.RESIZE,test);
function test(e:Event):void {
//舞台改变时,重新设置MC的位置
mcPosition();
}
function mcPosition() {
/*
一个有缓动效果,一个没有。可以根据自己需要2选1,我用的是带缓动效果的。所以这段注释掉了
-----------------------没有缓动效果------------------------
//左上
mc_lefttop.x=0;
mc_lefttop.y=0;
//右上
mc_righttop.x=stage.stageWidth-mc_righttop.width;
mc_righttop.y=0;
//中间
mc_center.x=(stage.stageWidth-mc_center.width)/2;
mc_center.y=(stage.stageHeight-mc_center.height)/2;
//左下
mc_leftbottom.x=0;
mc_leftbottom.y=stage.stageHeight-mc_leftbottom.height;
//右下
mc_rightbottom.x=stage.stageWidth-mc_rightbottom.width;
mc_rightbottom.y=stage.stageHeight-mc_rightbottom.height;
*/
//--------------------------------有缓动效果的-------------------------------//
TweenLite.to(mc_lefttop,0.5,{x:0,y:0,ease:Expo.easeOut});
TweenLite.to(mc_righttop,0.5,{x:stage.stageWidth-mc_righttop.width,y:0,ease:Expo.easeOut});
TweenLite.to(mc_center,0.5,{x:(stage.stageWidth-mc_center.width)/2,y:(stage.stageHeight-mc_center.height)/2,ease:Expo.easeOut});
TweenLite.to(mc_leftbottom,0.5,{x:0,y:stage.stageHeight-mc_leftbottom.height,ease:Expo.easeOut});
TweenLite.to(mc_rightbottom,0.5,{x:stage.stageWidth-mc_rightbottom.width,y:stage.stageHeight-mc_rightbottom.height,ease:Expo.easeOut});
}
mcPosition();//一定要加上这句啊。本人就犯错了。否则你刷新网页的时候它会又跑回最原来的位置。
flash中的代码就这么多。但是具体放到网页中的时候还要注意一下几点:
1.把flash的宽和高都设置成100%;
2.把网页的页边距设置成0;
3.就是浏览器兼容问题了。我用的ie8,刚开始高度不能100%;为了确保多浏览器(IE6,IE7,IE8,Firefox)支持,需要在Style中加入一下代码:
html, body, object
{
width:100%;
height:100%;
display:block;
}
html
{
/* hides the browser's scrollbars */
overflow:none;
}
body
{
margin:0;
padding:0;
}
------------------------------------------------------------------------------------------------