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._ro= 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.
Содержание 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...