Scripting animation with ActionScript 2.0
479
To pan an instance on the Stage using code:
1.
Create a new Flash document called
pan.fla
.
2.
Change the frame rate of the document to
24
fps in the Property inspector.
The animation is much smoother if you use a higher frame rate, such as 24 fps.
3.
Select Frame 1 of the Timeline, and add the following code to the Actions panel:
System.security.allowDomain("http://www.helpexamples.com/");
// initialize variables
var direction:Number = -1;
var speed:Number = 5;
// create clip to load an image into
this.createEmptyMovieClip("img_mc", 10);
// create a clip to use as a mask
this.createEmptyMovieClip("mask_mc", 20);
// use the Drawing API to draw/create a mask
with (mask_mc) {
beginFill(0xFF0000, 0);
moveTo(0, 0);
lineTo(300, 0);
lineTo(300, 100);
lineTo(0, 100);
lineTo(0, 0);
endFill();
}
var mcl_obj:Object = new Object();
mcl_obj.onLoadInit = function(target_mc:MovieClip) {
// set the target movie clip's mask to mask_mc
target_mc.setMask(mask_mc);
target_mc.onEnterFrame = function() {
target_mc._x += speed * direction;
// if the target_mc is at an edge, reverse the animation direction
if ((target_mc._x <= -(target_mc._width-mask_mc._width)) ||
(target_mc._x >= 0)) {
direction *= -1;
}
};
};
var my_mcl:MovieClipLoader = new MovieClipLoader();
my_mcl.addListener(mcl_obj);
my_mcl.loadClip("http://www.helpexamples.com/flash/images/image1.jpg",
img_mc);
Содержание 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...