简体   繁体   中英

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!

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
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM