Search code examples
actionscript-3classpropertiesmovieclip

AS 3 Get access to movieclip property


I created a class with MovieClip, in another class i created this object and added it into array. I can't get access to the property - Error #1069.

var square:MovieClip = new MovieClip();

    public function sq(s:Stage,c:int) {

    square.graphics.beginFill("0x164499");
    square.graphics.drawRect(0,0,200,c);
    square.graphics.endFill();
    addChild(square);

    }

Second class:

for(var i=0;i<4;i++){
    obj1 = new sq(stage,100);
    obj1.x=100;
    obj1.y=100;
    obj1.name="square"+i;

    var sarray:Array = new Array();
    sarray[i]=obj1;

    trace("parameter: "+sarray[0].c);

    stage.addChildAt(obj1,0);

}


Solution

  • You need define an variable c in sq

    var square:MovieClip = new MovieClip();
    
    public var c:int;
    public function sq(s:Stage,$c:int) {
    
        c = $c;
        square.graphics.beginFill("0x164499");
        square.graphics.drawRect(0,0,200,c);
        square.graphics.endFill();
        addChild(square);
    
    }
    

    And in the second class, I think you should define sarray outside the loop or use

      sarray.push(obj1);
    

    instead of

       sarray[i]=obj1;