package com.talkyun.rheaui.model { //MyWindow作用是爲titleWindow添加窗體的最小化和最大化的功能 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=1200; this.percentWidth=1000; //最大化狀態 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; } } }