<< 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 differences between the images
If you examine these two images carefully, you will see that:
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.
//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.
Notification Switch
Would you like to follow the 'Object-oriented programming (oop) with actionscript' conversation and receive update notifications?