?
Solved

Add Child dynamically in a loop

Posted on 2011-05-10
3
Medium Priority
?
262 Views
Last Modified: 2012-05-11
Hi,

I am creating new instances from a movie clip in library and adding it to a container on the stage. I also need to add a child to that already added child. Some thing like this in a loop.

var bar:YearBar=new YearBar();
myContainer.addChild(bar);

then I have to do this:
 var cube:Cube=new Cube();

I want to add this to the bar, so I did this:
myContainer.bar.addChild(cube);

But I am getting error.
Please note all these are happening in a loop and I need to create different number of these instances.

What am I doing wrong?

0
Comment
Question by:Angha110
3 Comments
 
LVL 17

Expert Comment

by:deepanjandas
ID: 35735151
Do this:
var bar:YearBar=new YearBar();
myContainer.addChild(bar);

var cube:Cube=new Cube();
bar.addChild(cube);

Open in new window


Warm Regards
Deepanjan Das
0
 
LVL 2

Accepted Solution

by:
Mohfath earned 2000 total points
ID: 35745227

Yes you see that even if the object is placed inside another object, you can still access it by calling its direct name so you dont need the 'myContainer' part in 'myContainer.bar.addChild(cube);'

Thanks deepanjandas

and for putting it in a loop you must use an array.

check this out:


   
var bar:YearBar=new YearBar();
myContainer.addChild(bar);

var myArray:Array = new Array();
myArray.push(mClip1);
myArray.push(mClip2);
myArray.push(mClip3);
myArray.push(mClip4);
myArray.push(mClip5);

var i:number;
for (i=0;i<myArray.Length;i++)
{
    bar.addChild(myArray[i]);
}

Open in new window

0
 

Author Comment

by:Angha110
ID: 35746199
Thank you for the responses. It works great.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
Suggested Courses
Course of the Month14 days, 2 hours left to enroll

807 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