AS3 - Can't access properties or methods of a MC child that has been added in script

Posted by Chris on Stack Overflow See other posts from Stack Overflow or by Chris
Published on 2010-04-24T17:41:19Z Indexed on 2010/04/24 17:43 UTC
Read the original article Hit count: 364

Filed under:
|

Hi All - I am still a bit of a beginner at AS3, so bear with me, please.

I have created a loop to instantiate tiles on a board. In the following example, "Gametiles" is an array containing objects of class "Tile" which is a class that extends MovieClip. "Game" is a MC that I added to the stage in the flash developing environment.

for(var i:uint=0;i < Gametiles.length;i++){
    var pulledTile = Gametiles[i];
    var tilename:String = "I_Tile_" + pulledTile.grid_y + "_" + pulledTile.grid_x;
    var createdTile = new InteractiveTile();
    pulledTile.addAnims(createdTile);
    Game.addChildAt(pulledTile, 0);
    Game.getChildAt(0).name = tilename;
}

The above code works - but with a tricky problem. If I did something like the following:

trace(Game.I_Tile_1_3.x);

I get "TypeError: Error #1010: A term is undefined and has no properties." However, I am able to access theses children in the following manner:

var testing = Game.getChildByName("I_Tile_1_3")
trace(testing.x);

This method is a bit cumbersome though. I really don't want to have to create a var and call getChildByName every time I want to interact with these properties or methods. How can I set up these children so that I can access them directly without the extra steps?

© Stack Overflow or respective owner

Related posts about as3

Related posts about addchild