Skip navigation
Currently Being Moderated

MovieClip in MovieClip in MovieClip in ....

Feb 24, 2012 10:31 PM


We have two main MovieClips, loaded from library.


var BigCircle:MovieClip = new BigCircle(); = "BigCircle";


var BigSquare:MovieClip = new BigSquare(); = "BigSquare";



When added, BigCircle has child with name SmallCircle, which itself has child SmallerCircle, which itself has child TinyCircle.

When added, BigSquare using ENTER_FRAME wants to get TinyCircle, for example its x.

BigSquare don't wanna see any vars, it wants a link!


In AS2 it was very easy:





AS3 has getChildByName. Let's try it:

trace(stage.getChildByName("BigCircle").getChildByName("SmallCircle"). getChildByName("SmallerCircle").getChildByName("TinyCircle").x); //ERROR 1061, even if use only two get...


trace(stage["BigCircle"]["SmallCircle"]["SmallerCircle"]["TinyCircle"]); //ERROR, even if use only two [ ], or dots between them

or combine

trace(stage.getChildByName("BigCircle").["SmallCircle"]); //AND WHAT NEXT?



Give BigSquare a link to TinyCircle.



  • Currently Being Moderated
    Feb 25, 2012 4:42 AM   in reply to XELAD111

    When you say things have names, what names are you referring to? For what I show below for the inner circles, the names are manually added instance names.


    You should not use the same variable name as the class of an object.  Try to follow conventions and use words starting with uppercase letters for class names and words starting with lowercase letters for object names/vars.  The same goes for the name property of the object... lowercase.


       var bigCircle:MovieClip = new BigCircle(); = "BigCircle";


       var bigSquare:MovieClip = new BigSquare(); = "bigSquare";



    Then, whatever code you have inside bigSquare targeting targeting TinyCircle could use...


       trace(MovieClip(parent).bigCircle.SmallCircle.SmallerCircle.TinyCircl e.x);

    Mark as:
  • Currently Being Moderated
    Feb 25, 2012 1:46 PM   in reply to XELAD111

    If you want to do things similarly to the way you did in AS2, then when you use the "parent" or "root" references you need to specify the class of the object that the parent/root is.  Most usually you can get away with using MovieClip(), although there are alternatives... you could even use Object(), but the bottom line is that AS3 requires you to cast the object to an appropriate classt... So where you might have used the following for AS2...





    in AS3 you need to use...




    Mark as:
  • Currently Being Moderated
    Feb 25, 2012 2:18 PM   in reply to XELAD111

    You shouldn't write the function into the listener like that, just keep it separate. 


    bigSquare.addEventListener(Event.ENTER_FRAME, clickbS);


    function clickbS(e:Event):void  {




    Your latest code does not show where they are added, so I don't know where to tell you they are either, and can't see that you named them properly to agree with your listener/handler code. 


    If you are assigning the listener in the main timeline, which appears to be the case since you are targeting bigSquare, then you should be able to target bigCircle directly without the need for the parent/root reference.  I thought you had the code in the timeline inside bigSquare such that you needed to use a parent/root reference.

    Mark as:
  • Currently Being Moderated
    Feb 25, 2012 5:07 PM   in reply to XELAD111

    I didn't see the error message until I got to the end, but I was able to see the error well before I got there.  You have not created an object called bigCircle, so you cannot expect to find one anywhere.  You created one named bC.


    Again, if you don't need to reference the root to target bC because it is already directly in scope with your code....


    function bS_ef(e:Event):void 


        trace(bC); // this is all you need since bC is in scope of this function


    Mark as:
  • Currently Being Moderated
    Feb 25, 2012 7:15 PM   in reply to XELAD111

    The "name" property of an object is just a string value, not an instance name.  You do not have a var named "bigCircle, you have a var namned bC.


    You are treating the name property like it is an instance name when you use...




    but it is not an instance name, it is just a string.   You should instead be using either...







    Mark as:
  • Currently Being Moderated
    Feb 26, 2012 5:00 AM   in reply to XELAD111

    I doubt you understand correctly based on what you just wrote.  Don't confuse a var with a name properrty, they are different animals.


    Do you need the name property, no.  Unless you have a whole bunch of those BigCircle objects being created, all you will need is the bC variable to target the BigCircle instance.  If you use the same variable name (bC) to create several, then it can come in handy to use the name property so that you can name them differently and target them separately, but still, you don't really need the name prperty.  You could just as well store the insdtances in an array and use the array to target them..


    You probably should spend some time reading the help documentation to learn about the name property.  I've tried to explain what it is, but if you don't get it, then you just need time to get used to it I guess.

    Mark as:
  • Currently Being Moderated
    Feb 28, 2012 9:54 AM   in reply to XELAD111

    If you havbe used AS2 for a long time then you should know that using a string the way you just tried to will not work...


        trace(??? "tinyCircle".x); // how would that work even in AS2? 


    Again, you are trying to use the name property as if it is an instance name, which it is not.


    I have no idea of the scope of your code since you are just displaying classes without showing how you implement them, but I would say you would need to change it to something like...



    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points