ForumsProgramming Forum

AS3: Count number of children movieclips?

Posted Oct 15, '13 at 1:45pm



1 post

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(); = "Clip_1";


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.


Posted Oct 16, '13 at 10:41am



1,258 posts


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++)

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

Reply to AS3: Count number of children movieclips?

You must be logged in to post a reply!