Flex:在PANEL的title上加一个button[转]
//转自:http://www.cnblogs.com/GFantasy/archive/2010/03/05/1678917.html
package{ import mx.containers.Panel; import mx.controls.Button; import flash.events.Event; import flash.events.MouseEvent; import flash.display.DisplayObject; import mx.effects.Resize; import mx.controls.Alert; import mx.controls.Label; [Event(name="restore")] [Event(name="maximize")] public class FlexPanel extends Panel{ private var state:int = 0; private var restoreBtn: Button; private var minBtn: Button; private var closeBtn: Button; [Embed("../assets/minICON.png")] // 这里我自定义了按钮外观 private var minIcon:Class; [Embed("../assets/minOverICON.png")] private var minOverIcon:Class; [Embed("../assets/restoreICON.png")] private var restoreIcon:Class; [Embed("../assets/restoreOverICON.png")] private var restoreOverIcon:Class; [Embed("../assets/closeICON.png")] private var closeIcon:Class; [Embed("../assets/closeOverICON.png")] private var closeOverIcon:Class; private var resize: Resize; private var effectTime: Number = 400; private static var _instance: FlexPanel; public function FlexPanel(){ super(); _instance = this; } public override function initialize():void{ super.initialize(); this.maxHeight = this.height; initEffect(); } private function setState(state:int):void{ this.state=state; if (state==0){ this.dispatchEvent(new Event('restore')); } else { this.dispatchEvent(new Event('maximize')); } } /* ************************************************* */ protected override function createChildren(): void { super.createChildren(); this.titleBar.addEventListener(MouseEvent.MOUSE_DOWN, doDrag); this.titleBar.addEventListener(MouseEvent.MOUSE_UP, doDrop); restoreBtn = new Button(); restoreBtn.addEventListener("click",doRestore); restoreBtn.setStyle("overIcon",restoreOverIcon); restoreBtn.setStyle("downIcon",restoreIcon); restoreBtn.setStyle("upIcon",restoreIcon); restoreBtn.visible=false; rawChildren.addChild(restoreBtn); minBtn = new Button(); minBtn.addEventListener("click",doMin); minBtn.setStyle("overIcon",minOverIcon); minBtn.setStyle("downIcon",minIcon); minBtn.setStyle("upIcon",minIcon); minBtn.visible = true; rawChildren.addChild(minBtn); closeBtn = new Button(); closeBtn.addEventListener("click",doClose); closeBtn.setStyle("overIcon",closeOverIcon); closeBtn.setStyle("downIcon",closeIcon); closeBtn.setStyle("upIcon",closeIcon); closeBtn.visible = true; rawChildren.addChild(closeBtn); } /* ************************************************** */ protected override function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{ super.updateDisplayList(unscaledWidth, unscaledHeight); } private function doMin(event:Event):void{ setState(1); minBtn.visible= false; restoreBtn.visible= true; minEffect(); //Alert.show(this.verticalScrollBar.toString()); } private function doRestore(event:Event) :void{ setState(0); minBtn.visible= true; restoreBtn.visible= false; restoreEffect(); } private function doClose(event:Event) :void{ this.visible = false; this.parent.removeChild(this); } private function doDrag(event:Event):void{ this.startDrag(); } private function doDrop(event:Event):void{ this.stopDrag(); } /* ********************************************************************************* */ protected override function layoutChrome(unscaledWidth: Number, unscaledHeight:Number):void { super.layoutChrome(unscaledWidth, unscaledHeight); var margin:int = 0; var pixelsFromTop:int = 6; var pixelsFromRight:int = 12; var buttonWidth:int = 18; var buttonHeight:int = 17; var distance:int = 7; var x:Number = this.width - buttonWidth*2 - distance - pixelsFromRight; var y:Number = pixelsFromTop; restoreBtn.setActualSize(buttonWidth, buttonHeight); restoreBtn.move(x,y); minBtn.setActualSize(buttonWidth, buttonHeight); minBtn.move(x,y); closeBtn.setActualSize(buttonWidth, buttonHeight); closeBtn.move(this.width - buttonWidth - pixelsFromRight,y); } /* ********************************************************************************* */ private function initEffect():void{ resize = new Resize(_instance); resize.heightTo = this.titleBar.height; resize.duration = effectTime; } private function minEffect():void{ resize.heightTo = this.titleBar.height; resize.end(); resize.play(); } private function restoreEffect():void{ resize.heightTo = this.maxHeight; resize.end(); resize.play(); } } }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?