Loading 10 MovieClips into an Array

Subscribe to Loading 10 MovieClips into an Array 6 posts, 3 voices

 
avatar for Mond Mond 49 posts
Anyone know of a for loop that would do this loading? I tried it this way:
        var str:String;
        var numArray:Array = new Array();

            for (i=0; i<10; i++)
            {
                str = "TT" + String(i);
                numArray[i] = new str();
            }
But I get compiler errors. I didn’t think it would work since there is nothing named str in the Library. The movie clips are named:TT0, TT1,...,TT9. All exported for ActionScript. The long, boring way would work of course:
numArray[0] = new TT0();
numArray[1] = new TT1();
.
.
.
numArray[9] = new TT9();
I am working in Flash CS3 in AS3.0. Thanks for any tricks you would like to share. Edit:I just thought of another way:
var numArray:Array = [new TT0(), new TT1(),...,new TT9()];
But that seems kinda wild!
 
avatar for Phantasmagoria Phantasmagoria 277 posts
This should work:
import flash.utils.getDefinitionByName;

var numArray:Array = new Array;

for (var i:int = 0; i<10; ++i) numArray.push(new (getDefinitionByName("TT" + i)));
 
avatar for Mond Mond 49 posts

Hi Phant. Thanks. I noticed the getDefinitionByName, but it seemed to advanced for me to figure out where to use it.

May I ask you a question….You seem to be the only person responding to my posts. Do I come off as arrogant or stupid or something? An unworthy newbie?

Don’t get me wrong, I truly appreciate you sharing your knowledge with me. I was just wondering…

 
avatar for Phantasmagoria Phantasmagoria 277 posts

You come off as somewhat of a newbie, but definitely not unworthy – someone who merely doesn’t have experience, not someone who is unpleasant to talk to or unable to learn. And your questions tend to be more insightful than most of what gets asked here.

I would wager that there simply aren’t that many programmers here who know the answers to the questions you ask. The skill of flash programmers in general is somewhat below average, and this forum doesn’t get all that much traffic.

 
avatar for Mond Mond 49 posts

Thank you. A “worthy newbie” sounds good for now. :) I like getDefinitionByName, I don’t need the numArray anymore.

 
avatar for Kalinium Kalinium 430 posts

Most newbie questions revolve around “how do i make a game i have a great idea”