g
Printer Friendly Version

editor  
BellaOnline's Flash and Animation Editor
 

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 →

Join us in the Flash forum.




Flash and Animation Site @ BellaOnline
View This Article in Regular Layout

Content copyright © 2013 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.



| About BellaOnline | Privacy Policy | Advertising | Become an Editor |
Website copyright © 2014 Minerva WebWorks LLC. All rights reserved.


BellaOnline Editor