I created a square and saved it as a movieclip called starContainer, i draged three of them on the stage and gave each one instance names in my flash cs6 named - goldStarContainer1, goldStarContainer2 and goldStarContainer3.
In my library i also have a movieclip of a gold star called goldStar
now i would like to do an if else statment and if its true add the gold star to the right starContainer.
public var starScreen:starScreen;
FYI // dynamic starScreen MovieClip is added on click
for( var i:int = 1; i < 4; i++ )
{
var levelNumStarNum:String = "L1star"+i;
var goldStarOnPage:goldStar = new goldStar();
if( shared.data[levelNumStarNum] == undefined )
{
// add no stars
}
else if( shared.data[levelNumStarNum] == 1 )
{
// this works
starScreen.goldStarContainer1.addChild(goldStarOnPage);
}
// but i would like to do something like this...
starScreen.goldStarContainer[i].addChild(goldStarOnPage);
I have tryed getChildByName but it keep giving me the error: Call to a possibly undefined method getChildByName through a reference with static type Class.
Try to change this:
starScreen.goldStarContainer1.addChild(goldStarOnPage);
to this:
DisplayObjectContainer(DisplayObjectContainer(starScreen).getChildByName("goldStarContainer"+i)).addChild(goldStarOnPage);
and see if it helps