I’m working on a project where I have a bunch of objects (same type) placed on the stage. What I want to do is add all of these objects to an array.
Here is my code, doesn’t work though. I know this isn’t the best way to go about adding things to the stage, but I have to do it this way.
package
{
import flash.events.Event
import flash.display.MovieClip;
public class Pellet_Manager extends MovieClip
{
var pellets:Array = new Array();
var pellet:Pellet;
public function Pellet_Manager()
{
var pellet:Pellet;
for (Pellet in stage)
{
pellet = Pellet;
pellets.push(pellet);
}
}
}
}
I have 5 instances of Pellet on the stage and I want to add them to the pellets array. Should I give each one an instance name like “pellet1” and loop through the stage checking for each one and adding it to the array?
Any help would be great.
1) To access the stage, you have add your manager to it, and write a callback function when it’s added to stage
2) Your foor loop has some errors
Hope it helps!