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
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
(Button.cacheAsBitmap property)
374
Working with Movie Clips
setting between
cacheAsBitmap
in the ActionScript 2.0 Language Reference.
{
and
true
false
cacheAsBitmap
.
Need help?
Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?