Add Child dynamically in a loop

Posted on 2011-05-10
Last Modified: 2012-05-11

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();

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

I want to add this to the bar, so I did this:;

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?

Question by:Angha110
    LVL 17

    Expert Comment

    Do this:
    var bar:YearBar=new YearBar();
    var cube:Cube=new Cube();

    Open in new window

    Warm Regards
    Deepanjan Das
    LVL 2

    Accepted Solution


    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 ';'

    Thanks deepanjandas

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

    check this out:

    var bar:YearBar=new YearBar();
    var myArray:Array = new Array();
    var i:number;
    for (i=0;i<myArray.Length;i++)

    Open in new window


    Author Comment

    Thank you for the responses. It works great.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
    In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
    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.
    The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

    760 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

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now