<< Chapter < Page | Chapter >> Page > |
//Increase or decrease the alpha value for the
// normal sky image.if (normalAlphaDecreasing) {
normalAlpha -= 0.005;}else {
normalAlpha += 0.005;}//end else
Compute new alpha value for the flipped sky image
Listing 10 uses the new alpha value for the normal sky along with the upper limit of the alpha value to compute a new alpha value for the flipped sky. As the alpha value forthe normal sky goes up, the alpha value for the flipped sky goes down and vice versa.
//Cause the alpha value for the flipped sky image
// to go down when the value for the normal sky// image goes up, and vice versa.
flippedAlpha = alphaLim - normalAlpha;
Apply the new alpha values to both sky images
Finally, Listing 10 sets the alpha value for each image to the new value.
//Change the alpha values for both sky images.
normalSky.alpha = normalAlpha;flippedSky.alpha = flippedAlpha;
}//end makeTheCloudsMove
The next time the images are rendered, the new alpha values will be in effect.
The CLICK event handler for the button
The button shown in Figure 1 provides the mechanism by which the viewer can interact with the program.
The code in Listing 4 registers a CLICK event handler on the button. Listing 12 shows that CLICK event handler. This method is called each time the user clicks the button.
//This method is a click handler on the button. It
// causes the lightening flash to occur and the// lightening bolt to be drawn.
private function onClick(event:MouseEvent):void {//Don't create another lightening bolt while the
// previous one is still in progress.if(!sizzlePlaying){
flashLightening();drawLightening();
}//end if}//end onClick
Create the lightening bolt and its flash
The code in Listing 12 first confirms that the sizzle sound is not currently being played. If not, Listing 12 calls the method named flashLightening to illuminate the scene, and calls the method named drawLightening to draw the lightening bolt.
The method named flashLightening
The method named flashLightening is shown in its entirety in Listing 13.
private function flashLightening():void {//Make the tree more visible. Apparently
// setting the alpha property has no effect on the// alpha byte values that have been individually
// set. Otherwise, the blue background would// become visible.
newTreeImage.alpha = 1.0;//Play a sizzle sound to accompany the flash of// lightening. Set a flag to prevent another sizzle
// sound from being played before this one finishes.sizzlePlaying = true;
channel = sizzle.play();//Register an event listener that will be called
// when the sizzle sound finishes playing.channel.addEventListener(
Event.SOUND_COMPLETE, soundCompleteHandler);//Change the background color to a dark yellow.redBkgnd = 128;
greenBkgnd = 128;blueBkgnd = 0;}//end flashLightening
Notification Switch
Would you like to follow the 'Object-oriented programming (oop) with actionscript' conversation and receive update notifications?