4,327
社区成员




<koje:CustomPanel id="k1" x="100" y="100" x.fullCu="0" y.fullCu="0" title="1" width.default="141" width.fullCu="1000" height.fullCu="800" height.default="146" restore="restoreState()" max="maxState('fullCu')">
<s:Button label="按钮" x="10" y="10"/> </koje:CustomPanel>
package com.koje
{
import flash.display.DisplayObject;
import flash.events.Event;
import flash.events.MouseEvent;
import mx.containers.Panel;
import mx.controls.Alert;
import mx.controls.Button;
[Event(name="restore")]
[Event(name="max")]
public class CustomPanel extends Panel
{
private var close_btn:Button;
private var max_btn:Button;
private var restore_btn:Button;
private var state:uint = 0;
[Embed("/images/panelClose.png")]
private var CloseIcon:Class;
[Embed("/images/panelHide.png")]
private var HideIcon:Class;
[Embed("/images/panelShow.png")]
private var ShowIcon:Class;
public function CustomPanel()
{
super();
this.title = "Custom Panel";
}
private function setState(s:uint):void
{
this.state = s;
if(state == 0)
this.dispatchEvent(new Event("restore"));
else
this.dispatchEvent(new Event("max"));
}
public function clickHandle(evt:MouseEvent):void
{
Alert.show("hide");
// this.visible = false;
}
override protected function createChildren():void
{
super.createChildren();
if(!this.close_btn)
this.close_btn = new Button;
this.close_btn.setStyle("overIcon",CloseIcon);
this.close_btn.setStyle("upIcon",CloseIcon);
this.close_btn.setStyle("downIcon",CloseIcon);
this.close_btn.x = 10;
this.max_btn = new Button;
this.max_btn.setStyle("overIcon",HideIcon);
this.max_btn.setStyle("upIcon",HideIcon);
this.max_btn.setStyle("downIcon",HideIcon);
this.max_btn.x = 50;
this.restore_btn = new Button;
this.restore_btn.setStyle("overIcon",ShowIcon);
this.restore_btn.setStyle("upIcon",ShowIcon);
this.restore_btn.setStyle("downIcon",ShowIcon);
this.restore_btn.x = 100;
this.rawChildren.addChild(max_btn);
this.rawChildren.addChild(restore_btn);
this.rawChildren.addChild(close_btn);
this.max_btn.addEventListener(MouseEvent.CLICK,doMax);
this.restore_btn.addEventListener(MouseEvent.CLICK,doRestore);
this.close_btn.addEventListener(MouseEvent.CLICK,clickHandle);
}
public function doMax(evt:MouseEvent):void
{
setState(1);
Alert.show("Max");
}
public function doRestore(evet:MouseEvent):void
{
setState(0);
Alert.show("Restore");
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth,unscaledHeight);
if(this.unscaledWidth >0)
this.visible = true;
else
this.visible = false;
var closeAsset:DisplayObject = this.close_btn.getChildByName("upIcon");
var maxAsset:DisplayObject = this.max_btn.getChildByName("upIcon");
var resAsset:DisplayObject = this.restore_btn.getChildByName("upIcon");
var margin:int = 4;
this.close_btn.setActualSize(closeAsset.width + margin,closeAsset.height + margin);
this.max_btn.setActualSize(maxAsset.width + margin,maxAsset.height + margin);
this.restore_btn.setActualSize(resAsset.width + margin,resAsset.height+ margin);
var pixelsFromTop:uint = 1;
var pixelsFromRight:uint = 10;
var btnwidth:uint = close_btn.width;
var x:Number = unscaledWidth - btnwidth - pixelsFromRight;
var y:Number = pixelsFromTop;
close_btn.move(x,y);
max_btn.move(x-35,y);
restore_btn.move(x-70,y);
}
}
}
<koje:CustomPanel id="k1" x="100" y="100" x.fullCu="0" y.fullCu="0" title="1" width.default="141" width.fullCu="1000" height.fullCu="800" height.default="146" restore="restoreState()" max="maxState('fullCu')">
<s:Button label="按钮" x="10" y="10"/>
</koje:CustomPanel>