using loop to access instance of a movie clip[

Posted on 2011-02-28
Medium Priority
Last Modified: 2012-05-11

I have movieclip in library which is being added to the stage. It has many smaller clips which are already named a1-a2-a3....

How can I access to them using a loop?

Using AS3
Question by:Angha110
  • 2

Accepted Solution

ute_arbeit earned 2000 total points
ID: 35002276
You can use the getChildByName () method of DisplayObjectContainer class (base class of MovieClip):

var numClips:int = mc.numChildren;
var child:DisplayObject;
for (var i:int = 1; i <= numClips; i++) {
	child = mc.getChildByName ("a" + i);

Open in new window


Author Comment

ID: 35002645
Great, I just did a test and I can trace the numChildren correctly. Now, what I need is to call the right instance to play the moviecliep.


it gives me error.
Each movie clip has 10 frame inside and I have stop(0 on the first frame. the play() will play the movieclip.

Author Comment

ID: 35002931
Hey, Thank you for the tip. I used an array to hold my clips and all works fine.
Thank you again.

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question