Action Script3 convert mouseEvents to touchEvents
Hi all, I have been following a tutorial on drag and drop using mouse buttons. I need to do this using touch gestures Touch and Drag.
I have the code to do this already but now either I need to start again or convert the code I already have.
I have movieClips as shapes and shape targets. The idea is for the correct moviclip to be dragged to the correct targets. If the movieclip hits the correct target it stops and if the wrong target it returns to its starting position. I know I can use hit test point to confirm the moviclips have gone to correct targets.
Like I say i have the code to do this with mouse clicks but not sure where to start for mobile devices. I'm new to coding and thought it would be simple to change from mouse to gestures but I don't think I have enough experience.
If some wise member could help me to connect this up I would be most grateful.
I have been using the function below. As far as I can tell the MovieClip is stored in a variable(item) when it is clicked on. Then when its released it either snaps to the reg point of the target or returns to its original positon.
item1_mc.addEventListener(MouseEvent.MOUSE_UP, item1Release);
item1_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);
function dragTheObject(event:MouseEvent):void {
var item:MovieClip=MovieClip(event.target);
item.startDrag();
var topPos:uint=this.numChildren-1;
this.setChildIndex(item, topPos);
}
function item1Release(event:MouseEvent):void {
var item:MovieClip=MovieClip(event.target);
item.stopDrag();
if (target1_mc.hitTestPoint(item.x,item.y)) {
item.x=target1_mc.x;
item.y=target1_mc.y;
} else {
item.x=orig1X;
item.y=orig1Y;
}
};
How to convert this for the gesture touch and drag?
Edit I have also posted this in Adobe Animate forum. Hope this is ok.
