ActionScript 3 手动拖动对象
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 手动拖动对象相关的知识,希望对你有一定的参考价值。
//------------------------------------------------------------------------------------
private function startDragHandler(e:MouseEvent = null):void
{
/*
Set custom cursor
*/
//if(!dragCursor) dragCursor = new DragCursor();
CursorManager.setCursor(DragCursor as Class,CursorManagerPriority.HIGH,0,0);
isMouseOffStage = false;
this.stage.addEventListener(Event.MOUSE_LEAVE,mouseLeftStage);
this.stage.addEventListener(MouseEvent.MOUSE_OUT,mouseOutStage);
this.stage.addEventListener(MouseEvent.MOUSE_OVER,mouseOverStage);
this.stage.addEventListener(MouseEvent.MOUSE_UP,stopDragHandler);
if(DataModel.getInstance().isAllowDragShirt)
{
moveFromPointX = this.mouseX;
moveFromPointY = this.mouseY;
addEventListener(Event.ENTER_FRAME,draggingHandler);
}
}
//------------------------------------------------------------------------------------
private function draggingHandler(e:Event = null):void
{
var targetX:Number = this.x+(this.mouseX-moveFromPointX);
var targetY:Number = this.y+(this.mouseY-moveFromPointY);
if(targetX>0 || targetX<maxMoveX) targetX = this.x;
if(targetY>0 || targetY<=maxMoveY) targetY = this.y;
this.x = targetX;
this.y = targetY;
moveFromPointX = this.mouseX;
moveFromPointY = this.mouseY;
}
//------------------------------------------------------------------------------------
private function stopDragHandler(e:MouseEvent = null):void
{
moveFromPointX=this.x;
moveFromPointY=this.y;
CursorManager.removeAllCursors();
if(DataModel.getInstance().isBusy) CursorManager.setBusyCursor();
this.stage.removeEventListener(Event.MOUSE_LEAVE,mouseLeftStage);
this.stage.removeEventListener(MouseEvent.MOUSE_OUT,mouseOutStage);
this.stage.removeEventListener(MouseEvent.MOUSE_OVER,mouseOverStage);
this.removeEventListener(Event.ENTER_FRAME,draggingHandler);
//stopDrag();
}
以上是关于ActionScript 3 手动拖动对象的主要内容,如果未能解决你的问题,请参考以下文章
在stage-Actionscript中保持较大的图像或对象可拖动
actionscript 3 通过拖动拉伸和旋转动画剪辑箭头
ActionScript 3 拖动图层基础知识
ActionScript 3 拖动整个弹性应用程序窗口
ActionScript 3 拖动滚动
ActionScript 3 拖动旋转AS3