Flash AS3 Get Child By Name

Say you wanted to grab a movie clip nested in side of a container movie clip. You can do this using getChildByName:

var referenceMC:MovieClip = MovieClip(containerMC.getChildByName(“targetMC”));

Now you have access to that targeted movie clip’s properties and for example could change the alpha to let’s say 50%

var referenceMC:MovieClip = MovieClip(containerMC.getChildByName(“targetMC”));
referenceMC.alpha = 0.5;

If you wanted to access multiple movie clips nested in a container by name you could use a for loop. This example assume that there are 5 movie clips named img0, img1, img2, img3…etc. We will loop through and set all movie clips alphas to 50%.

for (i=0; i<5; i++) {
var item_mc:MovieClip;
item_mc = MovieClip(cards.getChildByName(“img”+i));
item_mc.alpha=0.5;
}

You can also do this by using getAtIndex. See here:
http://am3media.com/site/flash/loop-through-child-movie-clips-in-as3-and-as2

You may also like...

2 Responses

  1. digitil says:

    or you can simply go like this:

    a movie clip named “trashcan” has a child movie clip called “plasticbag” and if you want to hide the plasticbag you would do this:

    trashcan.plasticbag.visible = 0;

    and presto! easy as pie (which cannot be said often when it comes to AS3)

  2. el cholo says:

    i have an mc named “yourMother” and has a child movie clip, named _rootFaggotSon, and you want to put this.dick inside _root.yourMother, get rid of the son delete._rootFaggotSon with plastic bag over head, and presto!

Leave a Reply