EasyManua.ls Logo

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

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...
Scripting animation with ActionScript 2.0 473
To fade an object by using the setInterval() function:
1. Create a new Flash document called fade2.fla.
2. Draw some graphics on the Stage, 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:
var alpha_interval:Number = setInterval(fadeImage, 50, img1_mc);
function fadeImage(target_mc:MovieClip):Void {
target_mc._alpha -= 5;
if (target_mc._alpha <= 0) {
target_mc._visible = false;
clearInterval(alpha_interval);
}
}
The setInterval() function behaves slightly differently than the onEnterFrame event
handler, because the
setInterval() function tells Flash precisely how frequently the
code should call a particular function. In this code example, the user-defined
fadeImage() function is called every 50 milliseconds (20 times per second). The
fadeImage() function decrements the value of the current movie clips _alpha property.
When the
_alpha value is equal to or less than 0, the interval is cleared, which causes the
fadeImage() function to stop executing.
7. Select Control > Test Movie to test the document.
The movie clip you added to the Stage slowly fades out.
For more information on user-defined functions, see “Defining global and timeline functions
on page 212. For more information on the
onEnterFrame event handler, see
onEnterFrame (MovieClip.onEnterFrame handler) in the ActionScript 2.0 Language
Reference. For more information on the
setInterval() function, see setInterval
function
in the ActionScript 2.0 Language Reference.
For an example of scripted animation in Flash, you can find a sample source file,
animation.fla, in the Samples folder on your hard disk.
In Windows, browse to boot drive\Program Files\Macromedia\Flash 8\Samples and
Tutorials\Samples\ActionScript\Animation.
On the Macintosh, browse to Macintosh HD/Applications/Macromedia Flash 8/Samples
and Tutorials/Samples/ActionScript/Animation.

Table of Contents

Related product manuals