关于as3中全屏显示的代码

      做生活 2007-7-11 13:1
关键就是下面语句

switch(stage.displayState) {
  case "normal":
    stage.displayState = "fullScreen";    
    break;
  case "fullScreen":
  default:
    stage.displayState = "normal";    
    break;
}

可以按自己需求写两个常用as 1、全屏点击方式

package {
  import flash.display.MovieClip;
  import flash.display.Sprite;  
  import flash.events.MouseEvent; 
  public class fullmask extends MovieClip {
    private var _Rect:Sprite;    
    public function fullmask(b_width:int,b_height:int) {      
      _Rect = new Sprite();
      _Rect.graphics.beginFill(0xff0000,0);
      _Rect.graphics.drawRect(0, 0, b_width,b_height);
      _Rect.graphics.endFill();
      addChild(_Rect);
      _Rect.buttonMode = true;
      _Rect.addEventListener(MouseEvent.CLICK, clickHandler)      
    }
        private function clickHandler(event:MouseEvent):void {
            switch(stage.displayState) {
                case "normal":
                    stage.displayState = "fullScreen";    
                    break;
                case "fullScreen":
                default:
                    stage.displayState = "normal";    
                    break;
            }

        }
  }
}

2、按钮点击方式

package {
  import flash.display.MovieClip;
  import flash.display.Sprite;  
  import flash.events.MouseEvent;
  import flash.text.TextField;
  import flash.text.TextFieldAutoSize;  
  public class fullbotton extends MovieClip {
    public function fullbotton(b_width:int,b_height:int,f_size:int) {
      var _Rect:Sprite = new Sprite();
      _Rect.graphics.beginFill(0xff0000,1);
      _Rect.graphics.drawRect(0, 0, b_width,b_height);
      _Rect.graphics.endFill();
      addChild(_Rect);
      _Rect.buttonMode = true;
          var t:TextField = new TextField(); 
      t.htmlText = "<FONT SIZE='"+f_size+"' color='#ffff00' ><b>点击此处切换观看模式(全屏/普通)</b></font>";
      t.autoSize = TextFieldAutoSize.LEFT;
      t.x=30;
      t.y=2;
      _Rect.addChild(t);
      var _Rect1:Sprite = new Sprite();
      _Rect1.graphics.beginFill(0x000000,0);
      _Rect1.graphics.drawRect(0, 0, b_width,b_height);
      _Rect1.graphics.endFill();
      _Rect.addChild(_Rect1);
      _Rect.addEventListener(MouseEvent.CLICK, clickHandler)      
    }
        private function clickHandler(event:MouseEvent):void {
            switch(stage.displayState) {
                case "normal":
                    stage.displayState = "fullScreen";    
                    break;
                case "fullScreen":
                default:
                    stage.displayState = "normal";    
                    break;
            }

        }
  }
}

另外,我米找到TextField不现实选取状态的方法,望高手指教。

标签集:TAGS:flash as3 example
回复Comments() 点击Count()

回复Comments

{commenttime}{commentauthor}

{CommentUrl}
{commentcontent}