<< Chapter < Page | Chapter >> Page > |
Register two event listeners
The first four statements in Listing 10 would be sufficient to play the effect if that was all that I wanted to do. In addition, however, myobjective is to illustrate the servicing of events that are dispatched due to changes of state within the program.
Seven different types of events
A Resize object dispatches seven different types of events including the following two:
The last two statements in Listing 10 register event listeners on the Resize object for both of those types of events.
Listing 10 also signals the end of the constructor for the Driver class.
Event handlers registered on the Resize object
The two event handlers registered on the Resize object by Listing 10 are shown in Listing 11.
private function startEffectHandler(
event:EffectEvent):void{textOut.text += "\nEffect Started!";
} //end event handler//--------------------------------------------------//private function endEffectHandler(
event:EffectEvent):void{textOut.text += "\nEffect Ended!";
} //end event handler
The first method named startEffectHandler is executed each time the Resize object dispatches an effectStart event. The second method named endEffectHandler is executed each time the Resize object dispatches an effectEnd event.
Output text at the start and the end of the effect
The text in the text area at the top of Figure 5 shows the result of executing the startEffectHandler method from Listing 11.
The text in the text area at the top of Figure 6 shows the result of executing the endEffectHandler method from Listing 11.
(Note the small size of the image at the end of the resize effect inFigure 6 as compared to the size of the image at the beginning of the resize effect in Figure 4.)
Methods of the Resize class
The Resize class defines several methods including the following six (in alphabetical order) :
Common event handler for the buttons
Listing 12 shows a common event handler that is used to service click events on all six of the buttons at the bottom of Figure 4.
private function btnHandler(event:MouseEvent):void{
if (event.target == startButton) {resize.play();//start the effect
startButton.enabled = false;}else if(event.target == pauseButton){
resize.pause();//pause the effect}else if(event.target == resumeButton){
resize.resume();//resume the effect after a pause}else if(event.target == reverseButton){
resize.reverse();//reverse the effect}else if(event.target == endButton){
resize.end();//end the effect prematurely}else{//reset the program to starting conditions
resize.end();image.width=240;
image.height=240;startButton.enabled=true;
} //end else} //end btnHandler
Notification Switch
Would you like to follow the 'Object-oriented programming (oop) with actionscript' conversation and receive update notifications?