<< Chapter < Page | Chapter >> Page > |
Even some of the classes that are subclasses of DisplayObject support events that don't involve direct user interaction such as the activate and deactivate events.
Events that don't involve user interaction are usually events that are dispatched because of some change of state within the program. Forexample, it is possible to register event listeners on object properties and cause other objects to be notified when the value of such properties change.
I will present and explain two programs in the remainder of this lesson. The first program named ActivateEvent01 provides a relatively simple illustration of servicing events that are dispatched independently of directuser interaction.
The second program named Effects03 is somewhat more substantial. It illustrates the servicing of events that are dispatched as a result of directuser interaction as well as events that are dispatched independently of direct user interaction.
A simple MXML file
Both of the programs that I will explain in this lesson use the same simple MXML file shown inListing 1 and also in Listing 14.
<?xml version="1.0" encoding="utf-8"?><mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"xmlns:cc="CustomClasses.*"><cc:Driver/></mx:Application>
This MXML code simply instantiates a new object of the Driver class in the cc namespace. Beyond that point, all program behavior is controlled by ActionScript code.
This is probably the most fundamental of all event-driven ActionScript programs. This program illustrates the activate and deactivate events. According to the EventDispatcher documentation, the activate event is "Dispatched when the Flash Player or AIR application gains operating system focus andbecomes active."
Similarly, the deactivate event is "Dispatched when the Flash Player or AIR application loses the operating system focus and is becominginactive."
Program screen graphics
The screen output for this program is shown in Figure 1. This output doesn't change during the running of the program.
Must run in debug mode
This program uses calls to the trace function to produce output text on the console screen. Therefore, you will need to compile and run theprogram in debug mode in the IDE to get matching results.
Gain and then lose operating system focus
If you start the program in debug mode, click somewhere inside the Flash window and then click somewhere in another window or on the desktop, you will cause the FlashPlayer to first gain and then lose the operating system focus. In other words, on the first click inside the Flash window, the Flash Player willbecome the active program. On the second click in another window, another program will become the active program.
Debug output in the system console
When you do that, output similar to that shown in Figure 2 should appear in the IDE console.
Notification Switch
Would you like to follow the 'Object-oriented programming (oop) with actionscript' conversation and receive update notifications?