利用include as的方式新增/覆寫函數, 可以使多種類別include需要的as而做群集性新增/覆寫函數.
- AddMethods.as
override public function sayHello():void { trace("Hello!"); } public function sayHello2():void { trace(this, " : Hello!"); }
- A.as
package { public class A extends SuperA { include "include/AddMethods.as"; } }
- B.as
package { public class B extends SuperB { include "include/AddMethods.as"; } }
- Main.as
package { import flash.display.Sprite; public class Main extends Sprite { public function Main() { var a:A = new A; a.sayHello2(); var b:B = new B; b.sayHello2(); } } }
範例檔案下載