AS3 - Children are not displayed
I have a container symbol called BoxContainer. This can contain an unknown number of Radio Button components. To add these, I have an array of Radio Buttons called boxes. This is part of the CheckBoxes class.
Here's my problem: When I add the radio buttons as children to the stage, from the frame itself, it works just fine. Ho开发者_JAVA技巧wever, I need to add it to the BoxContainer movie clip. I have tried:
On the frame:
for(var i in Checkbox.boxes)
{
BoxContainer.addChild(Checkbox.boxes[i]);
}
On the box container object
for(var i in Checkbox.boxes)
{
addChild(Checkbox.boxes[i]);
}
However, both of these do not work. When I run the flash, the radio buttons are not visible. How can I fix this?
First, is "boxes" a static member of the Checkbox class? It seems like an odd setup, but I'll assume that it is. Also, consider renaming "BoxContainer" to "boxContainer" as names with initial-caps are assumed to be classes, not objects in standard AS3 naming conventions.
The for...in
loop you're using is not going to work because i
becomes a reference to the object in the array, not the index of the array. Consider using a numeric for loop:
for (var i : uint = 0; i < Checkbox.boxes.length; i++)
{
BoxContainer.addChild(CheckBoxes.boxes[i]);
}
精彩评论