Skip to main content
Inspiring
May 15, 2013
Question

Using Array to create movie clips

  • May 15, 2013
  • 1 reply
  • 1599 views

I'm attempting to convert my teachers flash game to AS3 because I don't like AS2 all that much. I've got 90% of it converted. I just need to actually spawn the enemies for you to kill.

I've got an int called dragons that is set to 12. Then I have an array called movieList which is set to the number in the int dragons (I'm going to later add an option for you to upgrade the number of dragons in game. That's why it's set this way). Now, I need to spawn a dragon for each item in the array.

I've got this so far:


function initDragons():void

{

          for (var i:int=0;i< dragons;i++) {//Works

                    movieList = "dragon"+String(i);

                    movieList.push();

          }

          for(var j:int=0; j< movieList.length;j++){//Doesn't work

                    var movieList:dragon = new dragon();

                    addChild(movieList);

          }

}

the :dragon = new dragon(); is used because I have a MovieClip in my library that's linked to AS with the name dragon.

I didn't set an X or Y to the newly added movie clip's because they don't work. I'd like to get them to spawn first

This topic has been closed for replies.

1 reply

Inspiring
May 15, 2013

why using 2 loops?

try this:

function initDragons():void

{

          for (var i:int=0;i< dragons;i++) {//Works

                    movieList = "dragon"+String(i);

                    movieList.push();

                    var dragon:dragon = new dragon();

                    dragon.name = movieList;

                                                // you can get a reference to the any specific dragon later in your game by using

                                                // getChildByName("dragon8") or sth similar

                    addChild(dragon);

         }

}