For addChild(iconObject)
(second line inside function startAmoebaAttack()
), can anyone explain me where will iconObject
be added in? because it doesn't have any object or array before addChild
like iconObject.addChild(newSoldier);
private var iconObject:Sprite;
public function startAmoebaAttack() {
iconObject = new Sprite();
addChild(iconObject);
createSoldierIcon();
}
public function createSoldierIcon(){
soldierIcon = new Array();
for(var i:uint = 0; i<soldierLeft; i++){
var newSoldier:SoldierIcon = new SoldierIcon();
newSoldier.x = 65 + i *24;
newSoldier.y = 590;
iconObject.addChild(newSoldier);
soldierIcon.push(newSoldier);
}
}
It will automatically run it in
this
's context (same asthis.addChild(iconObject)
). In your casethis
is descendant ofDisplayObjectContainer
.