Recipe 10.1. Pausing a Movie After It Loads


Problem

You want to prevent the movie from playing when it loads.

Solution

Insert a stop( ) action on the first frame (or the first frame following the preloader), or, if applicable, set the play parameter/attribute in the HTML document to false.

Discussion

Because you want to pause playback automatically and immediately, rather than relying on a user-initiated event, such as a button press, you can add the stop( ) action to frame 1:

  1. Create a layer in the timeline called Actions.

  2. Select frame 1 of the Actions layer of the main timeline.

  3. Open the Actions panel (Window Actions, or F9, or Option-F9 on the Mac).

The stop( ) action doesn't require that you specify any additional information when you call it; it stops the current timeline (the timeline from which it is executed) as soon as it is called. Frame scripts are indicated by a small "a" character in the timeline in the keyframe in which you added the action. If you test the movie (using Control Test Movie), youll see that when the movie loads, it is paused in the first frame. When testing movies with ActionScript, you should test the actual .swf file (Control Test Movie) rather than using playback in the authoring environment (Control Play). Though you can activate simple actions during playback in the authoring environment (Control Enable Simple Frame Actions), it is best to get in the habit of testing the actual After you've used a stop( ) action, be aware that unless you create another script restarting playbackon a button, for examplethere is not necessarily a way for the user to get the movie to play again.

Users have some control over playback from the context menu, accessed by right-clicking (Windows) or Control-clicking (Macintosh) in the Flash player. Commands include Play, Rewind, Forward, and Loop. Making users rely on the context menu for playback is not good design for at least two reasons. One reason is that it is not an obvious user interface, and that makes the application less usable. Secondly, it is possible to customize the context menu such that the playback options are not displayed. As such, the context menu is not even a standard or consistent mechanism for playback control.


Although adding a stop( ) action is probably the easiest and most common way to stop a movie in the first frame, it is not the only way. You can also use HTML to prevent initial playback. To do so, set the play parameter of the <object> tag to false (for example, <param name=play value=false>) and likewise set the play attribute of the <embed> tag to false. The following code snippet shows the HTML code needed to embed a Flash .swf file in a web page, so that it is visible in all major browsers. The attributes needed to prevent playback are highlighted. This code is discussed in detail in Chapter 21.

 <object class codebase="http:// fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="550" height="400"  align="middle"> <param name="allowScriptAccess" value="sameDomain" /> <param name="movie" value="someMovie.swf" /> <param name="play" value="false" /> <param name="quality" value="high" /> <param name="bgcolor" value="#ffffff" /> <embed src="/books/2/703/1/html/2/ someMovi.swf" play="false" quality="high" bgcolor="#ffffff" width="550" height="400" name="someMovie" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/ getflashplayer" /> </object> 

Alternatively, you can use Flash to generate the HTML that sets the play parameter to false for both the <object> and <embed> tags. To do so, use the File Publish Settings HTML Paused At Start checkbox.

Generally, using stop( ) is better that relying on HTML parameters/attributes, because it works in all environments. The HTML option works only if you publish the SWF in an HTML document. If you publish the movie in a projector, or test it during authoring, HTML parameters and attributes aren't available.

See Also

Recipe 10.4, Recipe 21.1




Flash 8 Cookbook
Flash 8 Cookbook (Cookbooks (OReilly))
ISBN: 0596102402
EAN: 2147483647
Year: 2007
Pages: 336
Authors: Joey Lott

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net