g
Printer Friendly Version

editor  
BellaOnline's Flash and Animation Editor
 

eCard Project - Flash Script Assist Stop Action

In this tutorial, we will continue to build upon our FlashR CS4 eCard project. At this point, we have the animation completed for the eCard but this animation loops continuously. This is nice but it would be better if we could give the viewer the option to play the animation with a button.

Our goal for the next few tutorials is to add the ActionScript that will control when the movie plays. We will use a simple stop() code to stop the playback after the animation runs once. Then we will build a button that will allow the viewer to replay the eCard again. Open your working file into Flash CS4.

1. We want to stop the playback on the last frame of the animation. We will add the stop() code on Frame 75. But, first we need to add a new layer to the Timeline. Add a new layer above the Snow layer and name this new layer "Actions". Lock all other layers.

2. Right-click on Frame 75 of the Actions layer and add a Keyframe. We will "attach" our stop() action to this keyframe. Open the Actions panel (Window Actions). We will use Script Assist to quickly add our stop() code. Click on the Script Assist button to open the top pane. On the left of the Actions panel, you will see a menu of codes. Choose the following code.

flash.display MovieClip Methods stop

Flash will automatically give you the following code.

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

3. The "not_set_yet" before the stop() code tells us that we need to declare what we want to stop. We need to tell Flash to stop the main timeline, which we can identify with the "this" keyword. At the top of the Actions panel, type "this" into the Object field. Flash will automatically change the code to "this.stop()". You will also notice that Flash has placed a small "a" in Frame 75 on the Actions layer. This indicates that the ActionScript code has been "attached" to this keyframe.

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

4. Test your eCard and it will only play once through the animation. When the playback stops, the snowfall will stop, the "Let It Snow" message will be in its final position and all three of the colored lights will be visible.

Now, we are ready to make a replay button to allow the viewer to replay the animation.



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