flash网站浏览器窗口自适应<as3> 缓动的自适应窗口学习

本文介绍了一种使用AS3实现自适应布局的方法,通过TweenLite库为Flash元素添加缓动效果,确保在不同分辨率下元素能平滑移动到正确位置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

烦恼了很久的有自适应无缓动不知如何解决,终于从茫茫网海中找出来了,赶紧分享,学习。

-----------------------------------------------------------------------------------------------------------------------------------------

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;
        }

------------------------------------------------------------------------------------------------

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值