everisk
everisk

Reputation: 183

AS3 : Access MovieClip on stage

This may be a stupid questions but I can't find it.

I'd like to refer to movieClip onStage by looping though it for example, I have 10 movieclips name slot1 - slot12 then in my code

var hole:MovieClip;

function checkHit():void {
 hole = pirate.slot3;   // My problem is here how do i change this slot3 to slot 4,5,6 ... 
}

I know we can do a loop and i read about addChild but I dont want to keep creating new MC since they are already on stage.

Thank you!

Upvotes: 1

Views: 598

Answers (1)

laurent
laurent

Reputation: 90853

You can loop through the movie clips using the square brackets notation. For example:

function checkHit():void {
    // Make sure "i" is within the correct range
    for (var i:int = 1; i <= 12; i++) {
        var slot:* = pirate["slot" + i];
        // do something with slot
    }
}

Upvotes: 1

Related Questions