浏览 2363 次
锁定老帖子 主题:可拖拽的BOX
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2009-02-23
最后修改:2009-02-23
<?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> 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |