随笔-75  评论-193  文章-5  trackbacks-0

事件是实现对象通讯的一个重要手段,对于构建一个灵活的系统来说是非常必要的。在Flash Player 9中,将事件发送机制内建在了flash.events.EventDispatcher类中。所有需要发送事件的类都必须继承EventDispatcher类。
调用EventDispatcher类中的addEventListener( ) and removeEventListener( )方法,就可以注册或者移除事件监听器。EventDispatcher中还定义了dispatchEvent()方法,可以使用该方法发送事件。dispatchEvent()方法至少需要一个参数,即flash.events.Event对象或者它的子类。

原文如下:
Events are an important way for objects to communicate. They are essential for creating flexible systems. Flash Player 9, for example, has a built-in event dispatching mechanism in the flash.events.EventDispatcher class. All classes that dispatch events inherit from EventDispatcher (e.g., NetStream and Sprite). If you want to define a class that dispatches events, you can extend EventDispatcher, as follows:

package {
    import flash.events.EventDispatcher;
    public class Example extends EventDispatcher {

    }
}


The EventDispatcher class has public methods called addEventListener( ) and removeEventListener( ) that you can call from any instance of an EventDispatcher subclass to register event listeners. EventDispatcher also defines a protected method called dispatchEvent( ), which you can call from within a subclass to dispatch an event. The dispatchEvent( ) method requires at least one parameter as a flash.events.Event object or a subclass of Event.

posted on 2007-01-13 15:09 The Matrix 阅读(376) 评论(0)  编辑  收藏 所属分类: Flex

只有注册用户登录后才能发表评论。


网站导航: