あなたはそのようにそれをしません。動的とは、既に宣言されている関数をオーバーライドするのではなく、まだ宣言されていないアドホック プロパティを追加できるようにすることです。動的を抽象と混同しないでください。
代わりにこのようなことを試してください
public class Bullet extends Sprite{
public var speedX = 5;
public var speedY = 5;
public function update():void{
x += speedX;
y += speedY;
}
}
public class BulletFactory{
public static function getFastBullet():Bullet{
var result:Bullet = new Bullet();
result.speedX = result.speedY = 10;
return result;
}
}
好みに合わせて、speedX/speedY の公開/非公開の可視性を調整します。
一方、可能な限り文字通りの意味で「関数を動的にオーバーライド」したい場合は、常にこれがあります(ハックですが有効です)。
public class AbstractBullet extends Sprite{
public var update:Function; // <- Notice that function is just a variable here.
}
次に、弾丸ファクトリで、アドホック ベースで更新機能を割り当てることができます。update には署名が設定されていないため、タイプセーフの概念がすべて失われるため、これは「安全」ではないことに注意してください。また、呼び出す前に存在することを確認する必要があります。コンパイラの警告を回避したい場合は、null チェックを明示的に行う必要があります。
var f:Function;
// this is fine.
// it's particularly safe if
// f is a declared variable of type
// Function.
if(f != null) f();
// this is also fine,
// and is preffered if f is NOT
// a defined variable but instead
// a dynamically created (and therefore
// untyped) variable of a dynamic object.
// You would not want to "call" something
// that is not a function, after all.
if(f is Function) f();
// but this gives a warning
// even though the code works
// correctly at runtime.
if(f) f();