[AS3]as3自适应屏幕宽高的源代码实例
第一步:注释掉flex项目中的词句,[AS3]as3自适应屏幕宽高的源代码实例
第一步:注释掉flex项目中的词句 //[SWF(width="1250",height="650",backgroundColor="0X00AAFF")]
As代码如下:调用AddEvent接口
- package helper.fullScreen
- {
- import com.pblabs.engine.PBE;
- import com.pblabs.rendering2D.ui.SceneView;
- import config.ConfigMcWH;
- import config.ConfigSceneMap;
- import config.ConfigVar;
- import controller.publicCreateScene.CC_CreateScene;
- import controller.publicHeroMove.CC_HeroMove;
- import flash.display.Sprite;
- import flash.display.StageAlign;
- import flash.display.StageDisplayState;
- import flash.display.StageScaleMode;
- import flash.events.Event;
- import flash.events.TimerEvent;
- import flash.external.ExternalInterface;
- import flash.system.Capabilities;
- import flash.utils.Timer;
- public class CH_FullScreen
- {
- public function CH_FullScreen()
- {
- }
- private static var instanceVal:CH_FullScreen;
- public static function instance():CH_FullScreen
- {
- if(instanceVal==null)
- {
- instanceVal = new CH_FullScreen();
- }
- return instanceVal;
- }
- private var _sv:SceneView;
- private var _fun:Function;
- public function addAutoEvent(fun:Function=null):void
- {
- if(ConfigVar.screenIsAutoChange==true)
- {
- _fun = fun;
- PBE.mainStage.scaleMode=StageScaleMode.NO_SCALE;
- PBE.mainStage.align=StageAlign.TOP_LEFT;
- PBE.mainStage.addEventListener(Event.RESIZE, resizeDisplay2222);
- }
- }
- /**开启和关闭全屏的接口*/
- private var nowIsFullScreen:Boolean = false;
- public function fullScreen():void
- {
- if(nowIsFullScreen==false)
- {
- PBE.mainStage.displayState = StageDisplayState.FULL_SCREEN;
- nowIsFullScreen = true;
- }else{
- PBE.mainStage.displayState = StageDisplayState.NORMAL;
- nowIsFullScreen = false;
- }
- resizeDisplay2222();
- }
- private function resizeDisplay2222(event:Event=null):void
- {
- if(event!=null)
- {
- trace(event.target.stageWidth+" ... "+event.currentTarget.stageWidth);
- }
- ConfigSceneMap.nowScreenSeeW = PBE.mainStage.stageWidth;
- ConfigSceneMap.nowScreenSeeH = PBE.mainStage.stageHeight;
- var logStr:String = "尺寸发生了变化----------------\n";
- if(event!=null)
- {
- logStr += "event.target : "+event.target.stageWidth+","+event.currentTarget.stageHeight;
- }
- logStr += " PBE.mainStage : "+PBE.mainStage.stageWidth+","+PBE.mainStage.stageHeight;
- logStr += " \nscreenSeeW : "+ConfigSceneMap.screenSeeW+","+ConfigSceneMap.screenSeeH;
- logStr += " nowScreenSeeH : "+ConfigSceneMap.nowScreenSeeW+","+ConfigSceneMap.nowScreenSeeH;
- ConfigVar.logArr.push(logStr);
- /*
- ConfigSceneMap.nowScreenSeeW = (ConfigSceneMap.nowScreenSeeW <= 950) ? 950 : ConfigSceneMap.nowScreenSeeW;
- ConfigSceneMap.nowScreenSeeH = (ConfigSceneMap.nowScreenSeeH <= 560) ? 560 : ConfigSceneMap.nowScreenSeeH;
- ConfigSceneMap.nowScreenSeeW = (ConfigSceneMap.nowScreenSeeW >= 1250) ? 1250 : ConfigSceneMap.nowScreenSeeW;
- ConfigSceneMap.nowScreenSeeH = (ConfigSceneMap.nowScreenSeeH >= 650) ? 650 : ConfigSceneMap.nowScreenSeeH;
- */
- changeFloatSp();
- }
- //改变所有浮动元素的位置
- private function changeFloatSp():void
- {
- ConfigVar.PUBLICMENUSP.x = ConfigSceneMap.nowScreenSeeW - ConfigMcWH.MENUWH.x;
- ConfigVar.PUBLICMENUSP.y = ConfigSceneMap.nowScreenSeeH - ConfigMcWH.MENUWH.y;
- ConfigVar.MENUTOSP.x = 5;
- ConfigVar.MENUTOSP.y = ConfigSceneMap.nowScreenSeeH - ConfigMcWH.CHATWH.y;
- /*
- if(ConfigVar.DIVSP.width>0 && ConfigVar.DIVSP.height>0)
- {
- trace(ConfigSceneMap.nowScreenSeeW+" aaaaaaaaa "+ConfigVar.DIVSP.width +","+ConfigVar.DIVSP.width);
- var folotDivSpW:int = ConfigVar.DIVSP.width;
- var folotDivSpH:int = ConfigVar.DIVSP.height;
- ConfigVar.DIVSP.x = (ConfigSceneMap.nowScreenSeeW - folotDivSpW)/2;
- ConfigVar.DIVSP.y = (ConfigSceneMap.nowScreenSeeH - folotDivSpH)/2;
- trace(ConfigVar.DIVSP.x+","+ConfigVar.DIVSP.y);
- }
- */
- for(var i1:int=0,cnt1:int=ConfigVar.DIVSP.numChildren; i1<cnt1; i1++)
- {
- var obj1:* = ConfigVar.DIVSP.getChildAt(i1);
- if(obj1.visible==true)
- {
- trace(ConfigSceneMap.nowScreenSeeW+" aaaaaaaaa "+obj1.width +" "+obj1.name);
- obj1.x = (ConfigSceneMap.nowScreenSeeW - obj1.width)/2;
- obj1.y = (ConfigSceneMap.nowScreenSeeH - obj1.height)/2;
- }
- }
- }
- }
- }
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...