actionscript 3 - How do I reference two dynamic objects when checking for collision? -


i can't figure out how information on slot letter dropped above, letters snaps last slot, because it's 1 referenced properly. can tell me method check object(slot) letter dropped above? 2 kinds of movieclips create background letter , slot drop in.

var myformat:textformat = new textformat();     myformat.color = 0xffffff;     myformat.font = "verdana";     myformat.size = 35;       myformat.bold = true;     myformat.align = textformatalign.center;  var mystring:string = "firefly" mystring = mystring.touppercase(); var myarray:array = mystring.split('');  for(var i:number = 0; < mystring.length; i++) {      var mybogstav:bogstav = new bogstav();     var mybogstavslot:bogstavslot = new bogstavslot();      var mytext:textfield = new textfield();     mytext.selectable = false;     mytext.width = 50;     mytext.height = 50;      addchild(mybogstavslot);     addchild(mybogstav);     mybogstav.addchild(mytext);      mytext.defaulttextformat = myformat;     mytext.text = myarray[i];      mybogstavslot.name = "bogstavslot" + i;     mytext.name = "bogstav" + i;     mybogstav.name = "bogstavbg" + i;      mybogstavslot.x = i*60 + 10;     mybogstavslot.y = mybogstav.y - 100;     mybogstav.x = i*60 + 10;      mybogstav.addeventlistener(mouseevent.mouse_down, clicktodrag);     mybogstav.addeventlistener(mouseevent.mouse_up, releasetodrop); }  var startposition:point;  function clicktodrag(event:mouseevent):void {     setchildindex(event.target.parent, numchildren - 1);     event.target.parent.alpha = 0.6;      startposition = new point(event.target.parent.x, event.target.parent.y);      event.target.parent.startdrag(); }  function releasetodrop(event:mouseevent):void {        setchildindex(event.target.parent, 0);     event.target.parent.alpha = 1;     event.target.parent.stopdrag();      if (event.target.parent.hittestobject(movieclip)){         event.target.parent.x = movieclip.x;         event.target.parent.y = movieclip.y;      } else {         event.target.parent.x = startposition.x;         event.target.parent.y = startposition.y;     } } 

any appreciated.

simply use droptarget property (doc). property contains reference of displayobject on dragged item has been dropped.

function releasetodrop(event:mouseevent):void {        setchildindex(event.target.parent, 0);     event.target.parent.alpha = 1;     event.target.parent.stopdrag();     // here test if dragged item dropped on bogstavslot instance     // adapt condition needs     if (event.target.parent.droptarget bogstavslot ){         event.target.parent.x = event.target.parent.droptarget.x;         event.target.parent.y = event.target.parent.droptarget.y;      } else {         event.target.parent.x = startposition.x;         event.target.parent.y = startposition.y;     } } 

Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

How to call a javascript function after the page loads with a chrome extension? -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -