Hi all! I am calling on different types classes from within a loop. The objects can be of different types so therefore I am using the getDefinitionByName
method. here is a piece of my code:
for(var y = 0; y < mapH; y++)
{
brickHolder[y] = new Array();
for(var x = 0; x < mapW; x++)
{
var classRef = getDefinitionByName('com.objects.Brick2') as Class;
var brick:Brick2 = Brick2(new classRef());
brick.name = x+""+y;
brick.getBall(ball);
brick.getEngine(this);
brick.x = x * brick.bWidth + brick.bWidth;
brick.y = y * brick.bHeight + 100;
numberOfBricks += 1;
addChild(brick);
}
}
Only problem is I must cast this object into a specific variable:
var brick:Brick2 = Brick2(new classRef());
I thought about using a interface and casting it like this:
var brick:IBrick = IBrick(new classRef());
But I got an error when I tried to call on methods. The interface is blank; doesn't have any methods in it. I am not sure if that makes a difference. But the parent class inherits it and the subclasses inherit the parent class. Can I instead use the parent class?
var brick:ParentBrick2 = ParentBrick2(new classRef());
In a nutshell, what can I do to loosely cast these objects so I am able to use any subclass methods that get called?