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

热门文章推荐

请稍候...

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

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