Search code examples
flashdynamicvariablesactionscript-2movieclip

Dynamically accessing nested movie clips in flash actionscript 2


I have a nested movie clip instance that I want to access. The path to the movie clip is defined by two variables ( similar to a row and column).

I am already dynamically accessing the parent movie clip like this:

eval("row" + ActiveRow)

Now I want to access one of row(#)'s children called let(#) dynamically.

Here are my best guesses at accomplishing the task (neither one works):

var i:number;

eval("row" + ActiveRow + ".let" + i) or eval("row" + ActiveRow).eval("let" + i)

Thanks a lot for your effort and possible solution..


Solution

  • you could try

    this["row" + ActiveRow]["let" + i]
    

    What would be better though is if when you create the instances you put them in an array... so maybe

    var rowClips : Array = [];
    
    for (var i : int = 0; i < 10; i++)
    {
         var row : MovieClip = this.createEmptyMovieClip("row" + i, i);
    
         rowClips.push(row);
    }
    

    you can then call it by

    rowClips[i];
    

    Obviously depending on the situation there could be different logic to adding your MovieClips to an Array but essentially it's a much nicer way to store references to your MovieClips.