ResizeTtitleWindow

package Classes
{
  import flash.events.MouseEvent;
 
  import mx.containers.TitleWindow;
  import mx.controls.Button;

  public class MyWindow extends TitleWindow
  {
    public function MyWindow()
    {
      super();
      this.showCloseButton=true;
    }
    protected var maxSizeButton:Button; //最大化按钮
    protected var minSizeButton:Button; //最小化按钮
   
    //正常状态下窗口的大小、位置
    protected var normalX:int,normalY:Number,normalWidth:int,normalHeight:int;
   
    //初始状态
    protected var winState:String="normal";
   
    override protected function createChildren():void
    {
      super.createChildren();
     
      //创建最大化按钮
      this.maxSizeButton=new Button();
      this.maxSizeButton.width=this.maxSizeButton.height=16;
      this.maxSizeButton.y=6;
      //添加最大化事件
      this.maxSizeButton.addEventListener(MouseEvent.CLICK,OnMaxSize);
      this.titleBar.addChild(this.maxSizeButton);
     
      //创建最小化按钮
      this.minSizeButton=new Button();
      this.minSizeButton.width=this.minSizeButton.height=16;
      this.minSizeButton.y=6;
      //添加最小化事件
      this.minSizeButton.addEventListener(MouseEvent.CLICK,OnMinSize);
      this.titleBar.addChild(this.minSizeButton);
    }
    protected function OnMaxSize(e:MouseEvent):void
    {
      if(winState=="normal")
      {
        //保存正常状态下窗口位置、大小
     normalX=this.x;
        normalY=this.y;
        normalHeight=this.height;
        normalWidth=this.width;
       
        //设置为最大化状态
     this.x=0;
        this.y=0;
        this.percentHeight=100;
        this.percentWidth=100;
       
        //最大化状态
        this.winState="max";
      }
      else if(this.winState=="max")
      {
      //恢复正常状态下窗口位置、大小
        this.x=this.normalX;
        this.y=this.normalY;
        this.width=this.normalWidth;
        this.height=this.normalHeight;
       
        //正常状态
        this.winState="normal";
      }
    }
    protected function OnMinSize(e:MouseEvent):void
    {
      //最小化,简单隐藏
      this.visible=false;
    }
    override protected function layoutChrome(unscaledWidth:Number,
                                             unscaledHeight:Number):void
    {
      super.layoutChrome(unscaledWidth,unscaledHeight);
      //设置两个新添的按钮的位置
      this.maxSizeButton.x=this.titleBar.width-43;
      this.minSizeButton.x=this.titleBar.width-60;
     
      //调整状态文本的位置,左移一段位置
      this.statusTextField.x-=32;
    }
  }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值