<< Chapter < Page Chapter >> Page >

Compute new alpha value for the normal sky image.

//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.

Compute new alpha value for the flipped sky image.

//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.

Apply the new alpha values to both sky images.

//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.

The click event handler for 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.

The method named flashlightening.

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

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Object-oriented programming (oop) with actionscript. OpenStax CNX. Jun 04, 2010 Download for free at http://cnx.org/content/col11202/1.19
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with actionscript' conversation and receive update notifications?

Ask