A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Get Children Of A Child

  1. #1
    Junior Member
    Join Date
    Feb 2010

    Get Children Of A Child

    I have a movieclip called "myClip" and I add a random child to myClip which is either "myChild1", "myChild2", or "myChild3" and inside of all of these is a child called "myLittleChild".

    How would I call on the child "myLittleChild"?

  2. #2
    Senior Member
    Join Date
    Feb 2006
    Düsseldorf, Germany
    if i undestood correctly the structure looks like this:

    | |-myLittleChild
    | |-myLittleChild
    | |-myLittleChild
    | |-myLittleChild

    If you add to "myClip" just one child, then you need to use
    Actionscript Code:
    littleChild = myClip.getChildAt ( 0 )
    littleChild.myLittleChild //access your child
    If you have more than one child then you need to use
    Actionscript Code:
    littleChild = myClip.getChildByName ( 'myChild1' )
    littleChild.myLittleChild //access your child
    there is a place for those who dare to dream...

    Flash Developer
    D-42117 WUPPERTAL

  3. #3
    Will moderate for beer
    Join Date
    Apr 2007
    Austin, TX
    The property syntax (that is parentname.childname) only works if there are properties by those names. And there will only be properties by those names if A) you placed them through the IDE where flash attempts to "make things easier" by creating these properties for you or B) you create the properties yourself when adding the children through code.

    If you added these through code and the names you've given us are actually instance names (as opposed to library names or class names), then you can use either getChildAt or getChildByName to get children.

    In your case, since you just want the first child of the first child, the most robust way would be:
    var littleChild:MovieClip = MovieClip(DisplayObjectContainer(getChildAt(0)).getChildAt(0));
    Actually, the most robust way would be to simply retain a reference to littleChild when you add it so that you don't have to traverse the display list at all to get it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width

HTML5 Development Center