I am just trying to grasp a simple concept of utilizing loops, addChild, and eventListeners. My goal is to use a loop to create multiple instances of the same type of object from my library (called Ball), and when one is clicked, have it move “above” all other instances on the stage (and eventually drag, but that’s easy enough to make happen later). My current code attempt is:
for(var i:uint = 0; i<=10;i++)
var my_ball:Ball = new Ball() //new instances of Ball from library export
addChild(my_ball) //place ball in displayList
my_ball.name = “ball_”+i+"_mc" //give unique instance name to each ball
my_ball.x= (my_ball.width*.9)*i //spread balls across screen with slight overlap
//**WHAT SHOULD GO HERE?
addChild(event.target.name) //i want the clicked instance to be added to top of display list but what i have //obviously returns the clicked instance's NAME, which is NOT what i need... //i need to addChild(my_ball) NOT addChild(ball_#_mc) //also, do i need to remove the targeted child or will adding it //a second time automatically cause the "original" to be removed?
thanks in advance for any guidance