Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 20. Events and the Event Flow > The EventDispatcher Class

20.2. The EventDispatcher Class

At the root of event dispatching is the EventDispatcher class. You'll find that many classes in ActionScript 3.0 (including all display objects and many networking classes) already extend EventDispatcher, making the logistics of sending events quite convenient.

20.2.1. Using EventDispatcher

Let's walk through the process of triggering, dispatching, and receiving events. The first thing you need is an event dispatcher. In this example, let's create a Thermometer to measure temperatures. The Thermometer will also be able to notify anyone who's interested in the temperature. You'll do this by making Thermometer a subclass of EventDispatcher. You'll also add a public setter function for changing the temperature. In this setter, you'll call dispatchEvent(), defined in the superclass EventDispatcher, to notify other objects when the temperature changes:


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial