actionscript 3 - Drag and Drop AS3 - Simple snap to original place -


creating game drag , drop type there no "target areas (as when hover on button, plays video) want when drag items videos, if release item, snaps place.

here code have right now...

mc_d4.addeventlistener(mouseevent.mouse_down, dragd4); stage.addeventlistener(mouseevent.mouse_up, dragstop4); function dragd4(e:event):void { mc_d4.startdrag(); } function dragstop4(e:event):void {     mc_d4.stopdrag(); } 

you have save location of current dragged item somewhere. easy solution save in variable

var startposition:point;  mc_d4.addeventlistener(mouseevent.mouse_down, dragd4); stage.addeventlistener(mouseevent.mouse_up, dragstop4);  function dragd4(e:event):void {    mc_d4.startdrag();    startposition = new point( mc_d4.x, mc_d4.y); }  function dragstop4(e:event):void {    mc_d4.stopdrag();    //set or tween position     mc_d4.x = startposition.x;    mc_d4.y = startposition.y;     startposition = null;  } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -