actionscript 3 - How to drag and drop instances of a movieclip -


i have movieclip (star) in library , set it's class linkage name "star". use code call on stage.i want create multiple instances of star in same position , draggable unfortunately manage create 2 instances of movieclip , 1 draggable.i need code. thank you.

var stars:array =  []; var star:star = new star(); this.addchild(star); stars.push(star); star.x=550; star.y=490;  for(var i=0; i<stars.length; ++i)  {    trace(stars);    star.addeventlistener(mouseevent.mouse_down, clicktodrag);    star.addeventlistener(mouseevent.mouse_up, releasetodrop);  }  function clicktodrag(e:mouseevent):void {     e.target.startdrag();     var star:star = new star();     this.addchild(star);     stars.push(star);     star.x=550;     star.y=490; }  function releasetodrop(e:mouseevent):void {     e.target.stopdrag();     if (star.hittestobject(target))   {     trace("collision detected!");    e.target.removeeventlistener(mouseevent.mouse_down, clicktodrag);     }  else   {     trace("no collision.");   }  } 

you adding listener 1 star. add stars so,

var totalstars:int = 20;  for(var i=0; i<totalstars; i++) {           var star:star = new star();    this.addchild(star);    star.x=550;    star.y=490;     star.addeventlistener(mouseevent.mouse_down, clicktodrag);    star.addeventlistener(mouseevent.mouse_up, releasetodrop);     stars.push(star);  } 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -