So far nothing really happens when we click on our new button. Before we address the script involved, we should be good Flash programmers and give our button an “instance name.” Single click on the button (Be sure you are in the Scene 1 timeline and not the myButton timeline!) and look at the Properties panel.
The button currently has no , so we should give it one for it to be properly referenced from within our code. Let’s give it the instance name "instancename" to reflect its purpose. Now we need to write a function to produce an outcome of a mouse click. To do this, click on Frame 1 of Layer 1, and open the Actions panel either by choosing it from the Windows menu or by hitting the F9 key on your keyboard. (The panel should say “Actions – Frame” at the top. If it doesn’t, you need to click on Frame 1 of Layer 1 again.) Type the following lines of code into this panel:function onIntroClick(evt:MouseEvent):void {
gotoAndPlay(2);
}
instancename.addEventListener(MouseEvent.MOUSE_DOWN, onIntroClick);
// where it says MOUSE_OVER, you may also try CLICK, DOUBLE_CLICK, MOUSE_DOWN, MOUSE_UP, MOUSE_MOVE, MOUSE_OUT, MOUSE_OVER, MOUSE_WHEEL, ROLL_OUT, ROLL_OVER
// you may also try where it says gotoAndPlay, you may write gotoAndStop
No comments:
Post a Comment