An EFFECT_END handler for the Iris effect
When the bottom button is showing, the top button is disabled. Therefore, when the bottom button becomes hidden, the top button must be enabledor there will be no way to show the bottom button again.
Listing 7 registers an event handler on the Iris effect that is called each time the effect finishes playing. That event handler is shown inListing 10.
An effect_end handler for the iris effect.
private function endEffectHandler(
event:EffectEvent):void{btnA.enabled = true;
} //end event handler
The code in this method sets the enabled property of the top button to true making it possible to click that button to show the bottom button again.
That takes care of the code associated with clicking the bottom button.
A click event handler for the top button
Listing 6 registered a click event handler on the top button ( btnA ) . That event handler is shown in Listing 11. This method is called each timethe top button is clicked while it is enabled.
A click event handler for the top button.
private function btnAhandler(event:MouseEvent):void{
btnA.enabled = false;btnB.visible = true;
} //end btnAhandler
The code in this method disables the top button and sets the visible property of the bottom button to true.This causes the bottom button to dispatch a show event.
A show event handler was registered on the bottom button in Listing 6.
Beginning of the show event handler registered on the bottom button
That show event handler begins in Listing 12.
Beginning of the show event handler registered on the bottom button.
private function showHandler(event:FlexEvent):void{
//Make certain that none of the effects are playing.wipeEffect.end();
rotateEffect.end();glowEffect.end();//Select the effect or effects that will be
// played.if(effectCounter == 0){
wipeEffect.play();effectCounter++;//increment the effect counter.
This method is executed each time the visible property of the bottom button is changed from false to true. The transition of that propertyvalue from false to true causes the bottom button to dispatch a show event.
Stop all effects that may be playing
Listing 12 begins by calling the end method on three of the four Effect objects that were instantiated in Listing 5. If one of those effects is playing, calling the end method on the effect object causes the Flash Player to jump immediately to the end.
Determine which effect to play
Then Listing 12 begins executing a long if-else-if statement that determines which effect to play based on the current value of the variable named effectCounter that was declared and initialized to a value of zero in Listing 5.
Four possibilities
Depending on the current value of that counter, the program will play one of the following three effects or all three in parallel:
- WipeRight
- Rotate
- Glow
If the current value of the effect counter variable is 0, the last two statements in Listing 12 are executed. Otherwise, control passes to thetest at the top of Listing 13.