Drag and Drop

In the movie the 10 stars are generated dynamically using a loop.

Get Adobe Flash player

In this movie, we will use a loop to create 10 stars dynamically. We want to be able to drag any of the shapes after we create them.

Draw a star and make it a MovieClip named Star, and export for ActionScript. Remove the instance on the stage, all of the stars are created dynamically:

The code is shown below:

1
2
3
4
5
6
for(var i:int=0;i<10;i++) {
   var str:Star=new Star();
   str.x=Math.random()*stage.stageWidth;
   str.y=Math.random()*stage.stageHeight;
   this.addChild(str);
}
CODE

Download the movie

NEXT: Drag and drop dynamically generated shapes