A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [RESOLVED] Accessing Properties of "GrandChildren"

Hybrid View

  1. #1
    Junior Member
    Join Date
    Dec 2009
    Posts
    16

    resolved [RESOLVED] Accessing Properties of "GrandChildren"

    I am trying to access the properties of a "GrandChild" MovieClip.

    My DocumentClass adds an instance ("_parent") of the DisplayObject (linked from the library) to the stage:

    PHP Code:
    addChild(_parent); 
    I have a separate class that takes care of all the "_parent" related stuff, which is where I run into the problem. In this class, within a public function, I create a new instance of a movieclip and add it as a child to the parent. Then I add a child to the _child, aka a "grandchild"....all within a loop, and set some properties of the grandchild, like so:

    PHP Code:
    for (i=15i++){
       var 
    _child:MovieClip = new MovieClip;
       var 
    _grandchild:MovieClip = new MovieClip;

       
    _parent.addChild(_child);
       
    _child.addChild(_grandchild);
       
    _grandchild.i;} 
    Now, I am unable to "see" the grandchild's properties outside the loop. What's the proper way to get to the grandchild's properties? I've tried variations of the following:

    PHP Code:
    trace(_parent.getChildAt(1).getChildAt(1).x);
    trace(_parent._child.getChildAt(0).x); 
    Thanks,

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Code:
    trace(_parent.getChildAt(1).getChildAt(1).x);
    That way almost works. The children indexes start at 0, as all right-thinking indexes do. So there is a second child, but that child only has one child itself.
    Code:
    trace(_parent.getChildAt(0).getChildAt(0).x);
    That will trace the x value of the first child of the first child of _parent. BUT, why are you throwing away your references to these things if you want to use them later? Put your children in an array. And depending on how you want to access them, put the grandchildren in an array in the same scope, or as a property of each child.

    Also, your names are not very descriptive. Unless this is a family tree.

  3. #3
    Junior Member
    Join Date
    Dec 2009
    Posts
    16

    resolved

    Ah, yes. The array. I kind of forgot about them since AS2 now that AS3 has so many new things to try out. I've placed the children in arrays, and everything is much more accessible and all is working well. Thanks!

    (The variable names are just for my example to show what I was trying to do)
    Last edited by ben_tg; 03-04-2010 at 06:08 PM. Reason: resolved

Tags for this Thread

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