how addChild is being used in below AS3 code?

50 views Asked by At

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);
        }
    }
1

There are 1 answers

1
Ivan Chernykh On BEST ANSWER

It will automatically run it in this's context (same as this.addChild(iconObject)). In your case this is descendant of DisplayObjectContainer .