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;
var zapped:Boolean = false;
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();
}
if (zapped) {
bug_mc._y += 25;
}
};
588
Creating Interaction with ActionScript
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?