views:

53

answers:

1

I have a function that is called 3 times, I want times to assign it a name. How can I assign dynamic variable names to movieclips or do reference them by name or instancename?

var loadedMovie:MovieClip = new MovieClip();

loadedMovie.name = "mymovie";

loadedMovie = loadEvent.currentTarget.content; loadedMovie.x = 0; loadedMovie.y = 0;

addChild(loadedMovie);

mymovie.x = 20;

+1  A: 

refer to them by putting them into an array. Someting like this (i am guessing you create them as a response to an event):

private var loadedMCs:Array = [];
private function createMC(loadEvent:Event):void{
    var loadedMovie:MovieClip = loadEvent.currentTarget.content;
    loadedMovie.x = 20;
    loadedMovie.y = 0;
    addChild(loadedMovie);

    loadedMCs.push(loadedMovie);
    // you can name them too:
    loadedMovie.movieName = "mymovie"

}
// to find them:
for each( var mc:MovieClip in loadedMCs){
    if ( mc.movieName == "mymovie" ){
        trace ( "found" );
    }
}
sydd