Program Button with ActionScript and Script Assist

Program Button with ActionScript and Script Assist
We have completed our FlashR CS4 eCard animation, added the stop() code and built the button that our viewer will use to replay the animation a second or subsequent time. Now we are ready to attach some ActionScript 3 code to our button. This code will tell Flash to listen for a mouse event, such as our button being clicked. Then we will write a function to tell Flash what to do when the button is clicked. Our function will tell Flash to go back to the first frame and play the animation again.

Open your working file into Flash CS4.

1. First we need to add our Replay button onto the stage. We do not want the button to be available until the animation plays through the first time and stops. So, let's add the button to the last frame of the animation (Frame 75). Also to prevent the button from showing on the stage until Frame 75, we need to add a Keyframe. Right-click on Frame 75 of the Button layer and add a Keyframe. Flash will give you 74 blank frames and a keyframe on Frame 75.

Now, drag an instance (copy) of the Replay button from the Library onto the snow at the bottom right corner of the stage.

2. In order to control this instance (copy) of the Replay button with ActionScript, we need to give it a unique name. With the button selected, go to the Properties panel and replace "Instance Name" with "replay_btn". Now we can start working on the ActionScript.

3. Click on Frame 75 of the Actions layer and open the Actions panel. Here is our code so far.

import flash.display.MovieClip;
this.stop();

4. Let's tell Flash to listen for a mouse click on our replay_btn button. We will use Script Assist again to write our ActionScript. Click on the Script Assist button to open the top pane.

Click on the Plus sign to open the list of ActionScript codes. From this code list, click flash.events – IeventDispatcher – Methods – addEventListener. Flash will automatically update our code by adding these two lines.

Next →

Copyright 2018 Adobe Systems Incorporated. All rights reserved. Adobe product screen shot(s) reprinted with permission from Adobe Systems Incorporated. Adobe, Photoshop, Photoshop Album, Photoshop Elements, Illustrator, InDesign, GoLive, Acrobat, Cue, Premiere Pro, Premiere Elements, Bridge, After Effects, InCopy, Dreamweaver, Flash, ActionScript, Fireworks, Contribute, Captivate, Flash Catalyst and Flash Paper is/are either [a] registered trademark[s] or a trademark[s] of Adobe Systems Incorporated in the United States and/or other countries.





RSS
Related Articles
Editor's Picks Articles
Top Ten Articles
Previous Features
Site Map








Content copyright © 2023 by Diane Cipollo. All rights reserved.
This content was written by Diane Cipollo. If you wish to use this content in any manner, you need written permission. Contact Diane Cipollo for details.