<< Chapter < Page Chapter >> Page >

The third section -- apply the color components

The third section of code, consisting of the last three statements, uses the red, green, and blue color component values computed earlier to causethe color of the background to change. Note that this code maintains a 50-percent opacity value for the background color.

The method named makeTheCloudsMove

As you also saw in Listing 5, the Timer event handler also calls a method named makeTheCloudsMove each time the Timer object fires an event, or about three times per second. The purpose of thismethod is to create the illusion that the clouds shown in Figure 1 and Figure 2 are moving.

The one new thing

The procedure for accomplishing this is probably the only thing in this lesson that I haven explained in one form or another in an earlier lesson.

The image of the clouds shown in Figure 1 and Figure 2 is actually the superposition of two images, onein front of the other. The two images are shown in Figure 4 and Figure 5.

The image named normalsky.jpg.

Missing image
The image named normalsky.jpg.

The image named flippedsky.jpg.

Missing image
The image named flippedsky.jpg.

The differences between the images

If you examine these two images carefully, you will see that:

  • One is the mirror image of the other.
  • One has been given a green tint while the other has been given a magenta tint.

As mentioned earlier, the program displays both of these images, one on top of the other.

The illusion of movement...

The illusion of movement is achieved by causing the alpha transparency value of one image to go down while the alpha transparency value of the otherimage goes up and vice versa. In other words, the two images are caused to gradually fade in and out in opposition to one another.

Beginning of the method named makeTheCloudsMove

The code that accomplishes this begins in Listing 8.

Beginning of the method named makethecloudsmove.

//This method processes the alpha values of the// normal and flipped sky images. // The change in alpha values of the overlapping// images makes it appear that the clouds are // moving.private function makeTheCloudsMove():void {//Change the decreasing or increasing direction of // the changes in the alpha value for the normal// sky image when the alpha value hits the limits. if (normalAlphaDecreasing&&(normalAlpha<= 0.1)) { normalAlphaDecreasing = false;}else if (!normalAlphaDecreasing&&(normalAlpha>= alphaLim)) { normalAlphaDecreasing = true;}//end if

A saw tooth change in the alpha values

The alpha value for the normal sky image is caused to range from 0.1 to 0.5 in increments of 0.005 in a saw tooth fashion. At the same time, thealpha value for the other image is caused to range between the same limits in an opposing saw tooth fashion.

The code in Listing 8 keeps track whether the alpha values for the normal sky image are going up or going down, and flips the direction whenever the currentalpha value crosses one of the limits.

Compute new alpha value for the normal sky

Listing 9 uses that information to compute a new alpha value for the normal sky image.

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