User Guide
Deconstructing a sample script 195
mouseListener.onMouseUp = function() {
isDrawing = false;
};
Mouse.addListener(mouseListener);
5.
Select Control > Test Movie to test the movie. Click and drag your pointer to draw a line on
the Stage. Click the button to erase what you’ve drawn.
Deconstructing a sample script
In the sample SWF file zapper.swf (which you can view in Using Flash Help), when a user drags
the bug to the electrical outlet, the bug falls and the outlet shakes. The main Timeline has only
one frame and contains three objects: the ladybug, the outlet, and a reset button. Each object is a
movie clip instance.
The following script is attached to Frame 1 of the main Timeline:
var initx:Number = bug_mc._x;
var inity:Number = bug_mc._y;
reset_btn.onRelease = function() {
zapped = false;
bug_mc._x = initx;
bug_mc._y = inity;
bug_mc._alpha = 100;
bug_mc._rotation = 0;
};
bug_mc.onPress = function() {
this.startDrag();
};
bug_mc.onRelease = function() {
this.stopDrag();
};
bug_mc.onEnterFrame = function() {
if (this.hitTest(this._parent.zapper_mc)) {
this.stopDrag();
zapped = true;
bug_mc._alpha = 75;
bug_mc._rotation = 20;
this._parent.zapper_mc.play();
}