EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 472

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
472 Animation, Filters, and Drawings
Fading objects with code
When you work with movie clips on the Stage, you might want to fade the movie clip in or
out instead of toggling its
_visible property. The following procedure demonstrates how to
use an
onEnterFrame event handler to animate a movie clip.
To fade a movie clip by using code:
1. Create a new Flash document called fade1.fla.
2. Draw some graphics on the Stage using the drawing tools, or import an image to the Stage
(File > Import > Import to Stage).
3. Select the content on the Stage and select Modify > Convert to Symbol.
4. Select the Movie clip option and click OK to create the symbol.
5. Select the movie clip instance on the Stage and type img1_mc in the Instance Name text
box in the Property inspector.
6. Select Frame 1 of the Timeline, and add the following code to the Actions panel:
img1_mc.onEnterFrame = function() {
img1_mc._alpha -= 5;
if (img1_mc._alpha <= 0) {
img1_mc._visible = false;
delete img1_mc.onEnterFrame;
}
};
This code uses an onEnterFrame event handler, which is invoked repeatedly at the frame
rate of the SWF file. The number of times per second that the event handler is called
depends on the frame rate at which the Flash document is set. If the frame rate is
12 frames per second (fps), the
onEnterFrame event handler is invoked 12 times per
second. Likewise, if the Flash documents frame rate is 30 fps, the event handler is invoked
30 times per second.
7. Select Control > Test Movie to test the document.
The movie clip you added to the Stage slowly fades out.
You can modify the
_alpha property by using the setInterval() function instead of an
onEnterFrame event handler, as the next procedure shows.

Table of Contents

Related product manuals