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

[AS3]stage.stageWidth和stage.stageHeight取值为0的解决方法(2)

时间:2012-07-04 13:36CuPlayer.com
解决办法2 :加入Timer类,延时取得舞台尺寸 publicclassmainextendsSprite{ privatevarmyContextMenu:ContextMenu;//参数定义 publicvarstageWidth:int;//酷播cuplayer提示:舞台宽度 publicvarstageHeight:int;//

解决办法2 :加入Timer类,延时取得舞台尺寸

  1.           
  2. public class main extends Sprite {  
  3.         private var myContextMenu:ContextMenu;//参数定义  
  4.         public var stageWidth:int;//酷播cuplayer提示:舞台宽度  
  5.         public var stageHeight:int;//舞台高度  
  6.         //公开参数,使其他SWF可以使用  
  7. unction main() {  
  8.                 var tTimer:Timer=new Timer(1000,1);  
  9.                 tTimer.addEventListener(TimerEvent.TIMER,onTimer);  
  10.                 tTimer.start();  
  11.                 //延时实例化菜单,以读取到舞台尺寸  
  12.  
  13.         }  
  14.         private function onTimer(event:TimerEvent):void {  
  15.                 stage.scaleMode=StageScaleMode.NO_SCALE;  
  16.                 stage.align=StageAlign.TOP_LEFT;  
  17.                 //酷播cuplayer提示:维持舞台比例  
  18.                 stagestageWidth=stage.stageWidth;  
  19.                 stagestageHeight=stage.stageHeight;  
  20.                 //酷播cuplayer提示:取得舞台尺寸  
  21.         }  

热门文章推荐

请稍候...

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

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