flex titleWindow添加最小化和最大化按纽as

 
  1. <pre name="code" class="html">package com.talkyun.rheaui.model  
  2. {  
  3. //MyWindow作用是为titleWindow添加窗体的最小化和最大化的功能  
  4.   
  5.   import flash.events.MouseEvent;  
  6.   import mx.containers.TitleWindow;  
  7.   import mx.controls.Button;  
  8.   
  9.   
  10.   public class MyWindow extends TitleWindow  
  11.   {  
  12.     public function MyWindow()  
  13.     {  
  14.       super();  
  15.       this.showCloseButton=true;  
  16.     }  
  17.     protected var maxSizeButton:Button; //最大化按钮  
  18.     protected var minSizeButton:Button; //最小化按钮  
  19.      
  20.     //正常状态下窗口的大小、位置  
  21.     protected var normalX:int,normalY:Number,normalWidth:int,normalHeight:int;  
  22.      
  23.     //初始状态  
  24.     protected var winState:String="normal";  
  25.      
  26.     override protected function createChildren():void  
  27.     {  
  28.       super.createChildren();  
  29.        
  30.       //创建最大化按钮  
  31.       this.maxSizeButton=new Button();  
  32.       thisthis.maxSizeButton.width=this.maxSizeButton.height=16;  
  33.       this.maxSizeButton.y=6;  
  34.       //添加最大化事件  
  35.       this.maxSizeButton.addEventListener(MouseEvent.CLICK,OnMaxSize);  
  36.       this.titleBar.addChild(this.maxSizeButton);  
  37.        
  38.       //创建最小化按钮  
  39.       this.minSizeButton=new Button();  
  40.       thisthis.minSizeButton.width=this.minSizeButton.height=16;  
  41.       this.minSizeButton.y=6;  
  42.       //添加最小化事件  
  43.       this.minSizeButton.addEventListener(MouseEvent.CLICK,OnMinSize);  
  44.       this.titleBar.addChild(this.minSizeButton);  
  45.     }  
  46.     protected function OnMaxSize(e:MouseEvent):void  
  47.     {  
  48.       if(winState=="normal")  
  49.       {  
  50.         //保存正常状态下窗口位置、大小  
  51.         normalX=this.x;  
  52.         normalY=this.y;  
  53.         normalHeight=this.height;  
  54.         normalWidth=this.width;  
  55.          
  56.         //设置为最大化状态  
  57.         this.x=0;  
  58.         this.y=0;  
  59.          
  60.         this.percentHeight=1200;  
  61.         this.percentWidth=1000;  
  62.          
  63.         //最大化状态  
  64.         this.winState="max";  
  65.       }  
  66.       else if(this.winState=="max")  
  67.       {  
  68.         //恢复正常状态下窗口位置、大小  
  69.         thisthis.x=this.normalX;  
  70.         thisthis.y=this.normalY;  
  71.         thisthis.width=this.normalWidth;  
  72.         thisthis.height=this.normalHeight;  
  73.          
  74.         //正常状态  
  75.         this.winState="normal";  
  76.       }  
  77.     }  
  78.     protected function OnMinSize(e:MouseEvent):void  
  79.     {  
  80.       //最小化,简单隐藏  
  81.          this.visible=false;  
  82.     }  
  83.     override protected function layoutChrome(unscaledWidth:Number,  
  84.                                              unscaledHeight:Number):void  
  85.     {  
  86.       super.layoutChrome(unscaledWidth,unscaledHeight);  
  87.       //设置两个新添的按钮的位置  
  88.       thisthis.maxSizeButton.x=this.titleBar.width-43;  
  89.       thisthis.minSizeButton.x=this.titleBar.width-60;  
  90.        
  91.       //调整状态文本的位置,左移一段位置  
  92.       this.statusTextField.x-=32;  
  93.     }  
  94.   }   
  95. }  

相关文章

一:display:flex布局display:flex是一种布局方式。它即可以...
1. flex设置元素垂直居中对齐在之前的一篇文章中记载过如何...
移动端开发知识点pc端软件和移动端apppc端软件是什么,有哪些...
最近挺忙的,准备考试,还有其他的事,没时间研究东西,快周...
display:flex;把容器设置为弹性盒模型(设置为弹性盒模型之后...
我在网页上运行了一个Flex应用程序,我想使用Command←组合键...