-
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"?
-
if i undestood correctly the structure looks like this:
myClip
|-myChild1
| |-myLittleChild
|
|-myChild2
| |-myLittleChild
|
|-myChild3
| |-myLittleChild
|
|-myChild3
| |-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
VISTAPARK GMBH
BÄRENSTRASSE 11-13
D-42117 WUPPERTAL
-
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:
Code:
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|