0
votes

So I have this movievlip in my library, which is an instance of TestClass. There are four other movieclips in the parent movieclip. This is TestClass:

package  {
    import flash.display.MovieClip;

    public class TestClass extends MovieClip{

        public function TestClass() {
            for(var i:int = 0; i < numChildren; i++){
                trace(getChildAt(i));
            }
        }
    }   
}

However, this traces null four times, while it should trace [object MovieClip] right? Also, when I set the names of the movieclips under the accessibility tab and then use getChildByName('test'), it still traces null.

My question is: how can I get specific children from a movieclip in my library? For instance, when there are two children, I only want to get the child with the name test

1
That should work. Are you sure something else is not tracing "null"?Aaron Beall

1 Answers

2
votes

Firstly, I tried to reproduce your issue.

  1. I created a parent MovieClip and set a linkage name as "TestClass". Also, I added four child MovieClips to the TestClass.

enter image description here

  1. I created TestClass.as file with the same code.

In the output tab I see four [object MovieClip] lines. I don't know why you got null. Can you provide FLA file?


Why you set a name of child in the accessibility tab? You should set name in the "instance name" of properties panel.

enter image description here

So you can address to child by its name: child_1 in my case. trace(child_1); returns [object MovieClip].