给对象添加自定义事件

package {

    import flash.display.Sprite;

    import flash.events.Event;

    public class App extends Sprite {

        private var _test:Test;

        public function App() {

            _test=new Test();

            _test.addEventListener("TestEvent",mylogError);

            _test.Send();

        }

        protected function mylogError(e:Event):void{

            trace("logged");

        }

    }

}



package {

    import flash.display.Sprite;

    import flash.events.Event;

    public class Test extends Sprite {

        public function Send():void {

            this.dispatchEvent(new Event("TestEvent"));

        }

    }

}

上边 UP O  UP

先建个Test类  里有Send方法  当send方法执行时  调度  TestEvent 事件 

当给Test注册TestEvent事件后

当执行Send方法时  TestEvent事件就会执行

原文地址:https://www.cnblogs.com/mattins/p/2192128.html