I have a class Goo like this:
public class Goo extends Node
{
public function Update(dt:Number):void
{
// function to be overriden
trace("updating Goo");
}
}
and a subclass of Goo called GooX:
public class GooX extends Goo
{
override public function Update(dt:Number):void
{
trace("updating GooX");
}
}
and another called GooY:
public class GooY extends Goo
{
override public function Update(dt:Number):void
{
trace("updating GooY");
}
}
and then a Manager which creates Goo objects and updates them like this:
public class Manager
{
private var gooArray:Vector.<Goo> = new Vector.<Goo>();
public function Manager():void
{
var aGoo:Goo;
if (Math.random() >= 0.5)
{
aGoo = new GooX();
}
else
{
aGoo = new GooY();
}
gooArray.push(aGoo);
}
public function Update(dt:Number):void
{
for (var i:int = 0; i < gooArray.length; i++)
{
gooArray[i].Update(dt);
}
}
}
this code always shows "updating Goo" in the trace log. I tried also detecting which type is it by doing a gooArray[i] is GooX or gooArray[i] is GooY but it's always false for both. Even if I force a cast with gooArray[i] as GooX it will always say that the object is null.
Does anybody knows a way to do what I'm trying to do (let the Update of the child class being called instead of the one of the parent class)? Thanks.