·您当前的位置:首页 > 技术教程 > AS2与AS3技术 >

[AS3]as3自适应屏幕宽高的源代码实例

时间:2014-08-20 13:59酷播
第一步:注释掉flex项目中的词句,[AS3]as3自适应屏幕宽高的源代码实例

第一步:注释掉flex项目中的词句 //[SWF(width="1250",height="650",backgroundColor="0X00AAFF")]

As代码如下:调用AddEvent接口

  1. package helper.fullScreen 
  2. { 
  3.     import com.pblabs.engine.PBE; 
  4.     import com.pblabs.rendering2D.ui.SceneView; 
  5.      
  6.     import config.ConfigMcWH; 
  7.     import config.ConfigSceneMap; 
  8.     import config.ConfigVar; 
  9.      
  10.     import controller.publicCreateScene.CC_CreateScene; 
  11.     import controller.publicHeroMove.CC_HeroMove; 
  12.      
  13.     import flash.display.Sprite; 
  14.     import flash.display.StageAlign; 
  15.     import flash.display.StageDisplayState; 
  16.     import flash.display.StageScaleMode; 
  17.     import flash.events.Event; 
  18.     import flash.events.TimerEvent; 
  19.     import flash.external.ExternalInterface; 
  20.     import flash.system.Capabilities; 
  21.     import flash.utils.Timer; 
  22.  
  23.     public class CH_FullScreen 
  24.     { 
  25.         public function CH_FullScreen() 
  26.         { 
  27.         } 
  28.          
  29.         private static var instanceVal:CH_FullScreen; 
  30.         public static function instance():CH_FullScreen 
  31.         { 
  32.             if(instanceVal==null) 
  33.             { 
  34.                 instanceVal = new CH_FullScreen(); 
  35.             } 
  36.             return instanceVal; 
  37.         } 
  38.          
  39.         private var _sv:SceneView; 
  40.         private var _fun:Function; 
  41.         public function addAutoEvent(fun:Function=null):void 
  42.         { 
  43.             if(ConfigVar.screenIsAutoChange==true) 
  44.             { 
  45.                 _fun = fun; 
  46.                 PBE.mainStage.scaleMode=StageScaleMode.NO_SCALE; 
  47.                 PBE.mainStage.align=StageAlign.TOP_LEFT; 
  48.                 PBE.mainStage.addEventListener(Event.RESIZE, resizeDisplay2222); 
  49.             } 
  50.         } 
  51.          
  52.         /**开启和关闭全屏的接口*/ 
  53.         private var nowIsFullScreen:Boolean = false; 
  54.         public function fullScreen():void 
  55.         { 
  56.             if(nowIsFullScreen==false) 
  57.             { 
  58.                 PBE.mainStage.displayState = StageDisplayState.FULL_SCREEN; 
  59.                 nowIsFullScreen = true; 
  60.             }else{ 
  61.                 PBE.mainStage.displayState = StageDisplayState.NORMAL; 
  62.                 nowIsFullScreen = false; 
  63.             } 
  64.             resizeDisplay2222(); 
  65.         } 
  66.          
  67.         private function resizeDisplay2222(event:Event=null):void 
  68.         { 
  69.             if(event!=null) 
  70.             { 
  71.                 trace(event.target.stageWidth+" ... "+event.currentTarget.stageWidth); 
  72.             } 
  73.  
  74.             ConfigSceneMap.nowScreenSeeW = PBE.mainStage.stageWidth; 
  75.             ConfigSceneMap.nowScreenSeeH = PBE.mainStage.stageHeight; 
  76.              
  77.             var logStr:String = "尺寸发生了变化----------------\n"; 
  78.             if(event!=null) 
  79.             { 
  80.                 logStr += "event.target : "+event.target.stageWidth+","+event.currentTarget.stageHeight; 
  81.             } 
  82.             logStr += "  PBE.mainStage : "+PBE.mainStage.stageWidth+","+PBE.mainStage.stageHeight; 
  83.             logStr += "  \nscreenSeeW : "+ConfigSceneMap.screenSeeW+","+ConfigSceneMap.screenSeeH; 
  84.             logStr += "  nowScreenSeeH : "+ConfigSceneMap.nowScreenSeeW+","+ConfigSceneMap.nowScreenSeeH; 
  85.             ConfigVar.logArr.push(logStr); 
  86.  
  87.             /* 
  88.             ConfigSceneMap.nowScreenSeeW = (ConfigSceneMap.nowScreenSeeW <= 950) ? 950 : ConfigSceneMap.nowScreenSeeW; 
  89.             ConfigSceneMap.nowScreenSeeH = (ConfigSceneMap.nowScreenSeeH <= 560) ? 560 : ConfigSceneMap.nowScreenSeeH; 
  90.              
  91.             ConfigSceneMap.nowScreenSeeW = (ConfigSceneMap.nowScreenSeeW >= 1250) ? 1250 : ConfigSceneMap.nowScreenSeeW; 
  92.             ConfigSceneMap.nowScreenSeeH = (ConfigSceneMap.nowScreenSeeH >= 650) ? 650 : ConfigSceneMap.nowScreenSeeH; 
  93.             */ 
  94.             changeFloatSp(); 
  95.         } 
  96.          
  97.         //改变所有浮动元素的位置 
  98.         private function changeFloatSp():void 
  99.         { 
  100.             ConfigVar.PUBLICMENUSP.x = ConfigSceneMap.nowScreenSeeW - ConfigMcWH.MENUWH.x; 
  101.             ConfigVar.PUBLICMENUSP.y = ConfigSceneMap.nowScreenSeeH - ConfigMcWH.MENUWH.y; 
  102.              
  103.             ConfigVar.MENUTOSP.x = 5; 
  104.             ConfigVar.MENUTOSP.y = ConfigSceneMap.nowScreenSeeH - ConfigMcWH.CHATWH.y; 
  105.             /* 
  106.             if(ConfigVar.DIVSP.width>0 && ConfigVar.DIVSP.height>0) 
  107.             { 
  108.                 trace(ConfigSceneMap.nowScreenSeeW+" aaaaaaaaa "+ConfigVar.DIVSP.width +","+ConfigVar.DIVSP.width); 
  109.                 var folotDivSpW:int = ConfigVar.DIVSP.width; 
  110.                 var folotDivSpH:int = ConfigVar.DIVSP.height; 
  111.                 ConfigVar.DIVSP.x = (ConfigSceneMap.nowScreenSeeW - folotDivSpW)/2; 
  112.                 ConfigVar.DIVSP.y = (ConfigSceneMap.nowScreenSeeH - folotDivSpH)/2; 
  113.                 trace(ConfigVar.DIVSP.x+","+ConfigVar.DIVSP.y); 
  114.             } 
  115.             */ 
  116.             for(var i1:int=0,cnt1:int=ConfigVar.DIVSP.numChildren; i1<cnt1; i1++) 
  117.             { 
  118.                 var obj1:* = ConfigVar.DIVSP.getChildAt(i1); 
  119.                 if(obj1.visible==true) 
  120.                 { 
  121.                     trace(ConfigSceneMap.nowScreenSeeW+" aaaaaaaaa "+obj1.width +"  "+obj1.name); 
  122.                     obj1.x = (ConfigSceneMap.nowScreenSeeW - obj1.width)/2; 
  123.                     obj1.y = (ConfigSceneMap.nowScreenSeeH - obj1.height)/2; 
  124.                 } 
  125.             } 
  126.              
  127.         } 
  128.          
  129.     } 
  130. } 

热门文章推荐

请稍候...

保利威视云平台-轻松实现点播直播视频应用

酷播云数据统计分析跨平台播放器