0
votes

I got a Flash AS2 website and I need to get all the buttons inside an instancied movieclip (to define an specific property for each one). I've been searching for an hour or more, but I just got solutions for AS3! Could Someone help me?

Thank you all!

2

2 Answers

2
votes

Wow, AS2, haven't seen that in a while.

In AS2 clips that are created at runtime(via code) have positive depth values and clips that created at authortime(via Convert To Symbol) have negative depth values.

The easiest way to loop through is using for...in. Here is an example of that wrapped in a nice reusable function, which also allows you to optionally loop through all the nested clips inside a target clip:

var clips:Array = getChildrenOf(this,true);
var numClips:Number = clips.length;
for(var i:Number = 0 ;  i < numClips ; i++) trace("clip["+i+"]: " + clips[i]._name + " at depth " + clips[i].getDepth() + " in " + clips[i]._parent._name);

function getChildrenOf(target:MovieClip,recursive:Boolean):Array{
    var result:Array = [];
    for(var i in target){//loop through all properties
        if(target[i] instanceof MovieClip) {//look for movieclips
            result.push(target[i]);//found a clip add it to the result array
            if(recursive) result = result.concat(getChildrenOf(target[i],true));//concatenate children of clips at this level,recurse
        }
    }
    return result;
}

The second paramenter is optional, so if you omit it (e.g. getChildrenOf(this); ), you only get the children at the 1st level of depth inside your target movie clip (e.g. it's children, but not it's 'grandchildren')

HTH

0
votes

You first get the depth in the movieclip by using:

var depth:int = movieclip.getDepth();

And then you just iterate through the movieclip with a for-loop until you reach the value you get from getDepth:

for(var i:int = 0; i < depth; i++){
    trace(movieclip.getInstanceAtDepth(i));
}

This will get all instances inside the movieclip.

Have a read more about the methods in the reference in case you can't get this code working since it's not tested.

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/2/help.html?content=00001301.html

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/2/help.html?content=00001302.html