可拖拽的BOX

如果你想不用panel或TitleWindow而自定义popup,但是这个popup并不能拖动,则对box进行了improve.
<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" mouseDown="titleBar_mouseDownHandler(event)">
<mx:Script>
<![CDATA[
import mx.core.UIComponent;

private var regX:Number;
private var regY:Number;
public var documentParent : UIComponent;
public var closeButton : UIComponent;

/**
* Called when the user starts dragging a Panel
* that has been popped up by the PopUpManager.
*/
protected function startDragging(event : MouseEvent) : void
{
regX = event.stageX - documentParent.x;
regY = event.stageY - documentParent.y;

systemManager.addEventListener(
MouseEvent.MOUSE_MOVE, systemManager_mouseMoveHandler, true);

systemManager.addEventListener(
MouseEvent.MOUSE_UP, systemManager_mouseUpHandler, true);

systemManager.stage.addEventListener(
Event.MOUSE_LEAVE, stage_mouseLeaveHandler);
}
/**
* Called when the user stops dragging a Panel
* that has been popped up by the PopUpManager.
*/
protected function stopDragging() : void
{
systemManager.removeEventListener(
MouseEvent.MOUSE_MOVE, systemManager_mouseMoveHandler, true);

systemManager.removeEventListener(
MouseEvent.MOUSE_UP, systemManager_mouseUpHandler, true);

/* systemManager.stage.removeEventListener(
Event.MOUSE_LEAVE, stage_mouseLeaveHandler); */

regX = NaN;
regY = NaN;
}
/**
* @private
*/
private function titleBar_mouseDownHandler(event:MouseEvent) : void
{
// A mouseDown on the closeButton will bubble up to the titleBar,
// but it shouldn't start a drag; it should simply start the
// normal mouse/Button interaction.
if (event.target == closeButton)
return;
if (isNaN(regX) && documentParent.isPopUp)
startDragging(event);
}
/**
* @private
*/
private function systemManager_mouseMoveHandler(event:MouseEvent) : void
{
// during a drag, only the Panel should get mouse move events
// (e.g., prevent objects 'beneath' it from getting them -- see bug 187569)
// we don't check the target since this is on the systemManager and the target
// changes a lot -- but this listener only exists during a drag.
event.stopImmediatePropagation();
documentParent.move(event.stageX - regX, event.stageY - regY);
}
/**
* @private
*/
private function systemManager_mouseUpHandler(event:MouseEvent) : void
{
if (!isNaN(regX))
stopDragging();
}
/**
* @private
*/
private function stage_mouseLeaveHandler(event:Event) : void
{
if (!isNaN(regX))
stopDragging();
}
]]>
</mx:Script>
</mx:HBox>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值