EasyManua.ls Logo

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

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...
374 Working with Movie Clips
9. Select Frame 1 of the Timeline, and then add the following ActionScript to the
Actions panel:
import mx.transitions.Tween;
var star_array:Array = new Array();
for (var i:Number = 0; i < 20; i++) {
makeStar();
}
function makeStar():Void {
var depth:Number = this.getNextHighestDepth();
var star_mc:MovieClip = this.attachMovie("star_id", "star" + depth,
depth);
star_mc.onEnterFrame = function() {
star_mc._rotation += 5;
}
star_mc._y = Math.round(Math.random() * Stage.height - star_mc._height
/ 2);
var star_tween:Tween = new Tween(star_mc, "_x", null, 0, Stage.width,
(Math.random() * 5) + 5, true);
star_tween.onMotionFinished = function():Void {
star_tween.yoyo();
};
star_array.push(star_mc);
}
var mouseListener:Object = new Object();
mouseListener.onMouseDown = function():Void {
var star_mc:MovieClip;
for (var i:Number = 0; i < star_array.length; i++) {
star_mc = star_array[i];
star_mc.cacheAsBitmap = !star_mc.cacheAsBitmap;
}
}
Mouse.addListener(mouseListener);
10.
Select Control > Test Movie to test the document.
11. Click anywhere on the Stage to enable bitmap caching.
You’ll notice that the animation changes from appearing to animate at 1 frame per second,
to a smooth animation where the instances animate back and forth across the Stage. When
you click the Stage, it toggles the
cacheAsBitmap setting between true and false.
If you toggle caching on and off, as demonstrated in the previous example, it frees the data
that is cached. You can also apply this code for a Button instance. See
cacheAsBitmap
(Button.cacheAsBitmap property)
in the ActionScript 2.0 Language Reference.

Table of Contents

Related product manuals