摘自:AOL
Blog
import
mx.containers.Window;
import
mx.controls.SimpleButton;
import
mx.events.EventDispatcher;
[IconFile("ResizableWindowIcon.png")]
class ResizableWindow
extends
Window
{
static
var symbolName:String
= "ResizableWindow";
static
var symbolOwner:Object
= Object(ResizableWindow);
static
var
version:String
= "0.01";
var clipParameters:Object
= { };
static
var mergedClipParameters:Boolean
= UIObject.mergeClipParameters(
mx.containers.Window.prototype.clipParameters,
ResizableWindow.prototype.clipParameters);
private
var handle:SimpleButton;
private
var _oldx:Number;
private
var _oldy:Number;
[Inspectable(verbose=1, category="Skins")]
var skinResize:String
= "ResizeButton";
function MyComponent()
{
}
function init(Void):Void
{
super.init();
}
function
size(Void):Void
{
super.size();
}
private
function createChildren(Void):Void
{
super.createChildren();
var resizeObj:Object
= new
Object();
resizeObj.falseUpSkin = skinResize;
resizeObj.falseOverSkin = skinResize;
resizeObj.falseDownSkin = skinResize;
handle = createClassObject(SimpleButton,
"handle",
100,resizeObj);
handle.tabEnabled =
false;
handle.onPress =
startResize;
handle.onRelease =
stopResize;
handle.onReleaseOutside
= stopResize;
}
private
function
doLayout(Void):Void
{
super.doLayout();
handle.move(width-handle.width,
height-handle.height);
}
private
function startResize(Void):Void
{
this.useHandCursor=true;
this._parent._oldx=this._parent._xmouse;
this._parent._oldy=this._parent._ymouse;
this._parent.onMouseMove
= this._parent.resize;
}
private
function
resize(Void):Void
{
var dx =
_xmouse - _oldx;
var dy =
_ymouse - _oldy;
if((width>minWidth
&& height>minHeight
) || (dx>0 && dy>0))
setSize(width
+dx, height +dy);
_oldx=_xmouse;
_oldy=_ymouse;
}
private
function stopResize(Void):Void
{
this.useHandCursor=false;
delete
this._parent.onMouseMove;
this._parent.releaseFocus();
}
}