ForumsProgramming ForumAS3: Count number of children movieclips?

1 11085
JefferyWright
offline
JefferyWright
1 posts
Nomad

I have buttons that create specific movie clips such as a library object named "Clip_1":

function b_Add_Clip_1(event:MouseEvent):void
{
var b:MovieClip = new Clip_1();
b.name = "Clip_1";

container.addChild(b);
}

So I can add many Clip_1's, Clip_2's and so on, by their corresponding buttons.

I cannot figure out how to count the number of them that exist on the stage, however and I've looked all over the nets.

I would like the number of Clip_1 instances to display in a text field.

For example: If there are 20 on the stage, the text field should display 20, if one is removed, it should display 19.

I would be grateful for any helpful hints, thank you.

  • 1 Reply
weirdlike
offline
weirdlike
1,299 posts
Prince

I am away from my home at the moment so I didn't test, but I think this should work.

//name all children on MovieClip as i in your case MC is b
for(var i:int=0;i&ltMC.numChildren;i++)
{
trace(i);
}

----------------------------------------------
alternatively you can try

//create an array
private var testArray:Array;

//add this after you create movieclip
testArray.push( MC );

//for each
for each (var MC in testArray)
{
trace("movieClip on Screen"
}

good luck

Showing 1-1 of 1