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 document’s 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.
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...