1. 动态改变实例里面的方法实现
MyClass.as
- package Model
- {
- public class MyClass
- {
- public function MyClass()
- {
- }
- public var AlertFunc:Function = function():void
- {
- trace("what time is it now?");
- }
- }
- }
Sample9271.as
- package {
- import flash.display.Sprite;
- import Model.MyClass;
- public class Sample9271 extends Sprite
- {
- public function Sample9271()
- {
- var model:MyClass = new MyClass();
- model.AlertFunc();
- model.AlertFunc = AMFunc;
- model.AlertFunc();
- model.AlertFunc = PMFunc;
- model.AlertFunc();
- }
- internal function AMFunc():void
- {
- trace("Good Morning");
- }
- internal function PMFunc():void
- {
- trace("Good Afternoon");
- }
- }
- }