I have an Array
that stores instances of a class called Block
. The array is populated using myArray.push(world.create(Block));
. Block
contains a function: public function setup(_type:String, _color:uint):void
. I want to pass values to the Block
instance in the myArray.push(world.create(Block));
line of code.
I’ve tried:
var subType:String = "blueBlock";
var otherColor:uint = 0x1A1A1A;
myArray.push(Block(world.create(Block)).setup(subType, otherColor));
But when I go to access properties of the instance in that array index, I get an error on that line:
myArray[myArray.length - 1].x = x;
[Fault] exception, information=TypeError: Error #1010: A term is undefined and has no properties.
However, this works fine:
myArray.push(world.create(Block));
myArray[myArray.length - 1].type = subType;
myArray[myArray.length - 1].img.color = otherColor;
myArray[myArray.length - 1].x = x;
Can someone please help?