EasyManua.ls Logo

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

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 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);

Table of Contents

Related product manuals