Copy link to clipboard
Copied
Hey guys,
I've been trying to create a simple platformer game. What I want to do is when the game starts I want to create an array that contains all the instances of the MovieClip symbol "Platform". The instances themselves on the stage don't have names, I just want to create an array with all the instances of the Platform symbol. I've seen a few examples but they aren't quite the same as what I'm trying to do. How can I push the instances as MovieClips into an array?
Thanks
use the is keyword while going through the displaylist
and finding instances of certain Classes (linkage your MovieClip with Actionscript for this)
if(container.getChildAt(i) is Platform){
myPlatforms.push(container.getChildAt(i));
}
Copy link to clipboard
Copied
An array holds anything you like. In this case it would just be pushing references of a potential displaylist object.
It's as ease as:
var myPlatforms:Array = new Array();
myPlayforms.push(somePlatform);
// or if named instances
myPlatforms.push(getChildByName('instancename'));
That'll just push references of that platform into the array.
How are you generating the platforms? It doesn't NEED an instance name but for ease your array should have the scope necessary to add them where you create them.
Copy link to clipboard
Copied
The platforms are not added to the stage dynamically, I just placed them on the stage in the FLA file. They don't have instance names, I could just go through and name them but I'd like to know how to just create an array of instances of a certain symbol that are on the stage
I dont understand the first one :
myPlatforms.push(somePlatform);
What should be in place of "somePlatform" in my script? How do I actually push the platform instances into the array?
Copy link to clipboard
Copied
use the is keyword while going through the displaylist
and finding instances of certain Classes (linkage your MovieClip with Actionscript for this)
if(container.getChildAt(i) is Platform){
myPlatforms.push(container.getChildAt(i));
}
Copy link to clipboard
Copied
Perfect, thanks mocca! .
Find more inspiration, events, and resources on the new Adobe Community
Explore Now