How to Insert an SWF and Not Automatically Play It

Many website visitors find automatically playing media items annoying.
... BananaStock/BananaStock/Getty Images

SWF files often include timeline animations, which play within Web pages. When including an SWF file within a website, the SWF movie will automatically play as soon as it is loaded in the user's browser. If you do not want an SWF file to play automatically, you may need to edit the HTML code, JavaScript code, or in some cases the code inside the Flash file itself. Which option you choose will depend on the content of the SWF and on the surrounding HTML and JavaScript code in the Web page.

1 Embed Element

The embed element can write a Flash file into HTML. To include an SWF file in a page using an embed element, you can use the following sample markup:

<embed src="flash_file.swf" width="500" height="400"/>

The "src" attribute lists the name of the SWF file. The embed tag typically also lists additional attributes, optionally including one to control autoplay as follows:

<embed src="flash_file.swf" width="500" height="400" play="false"/>

The "play" attribute specifies that the SWF should not automatically play when it is loaded.

2 Object Element

The HTML object element allows Web pages to include SWF files. The following syntax snippet demonstrates the markup:

<object width="500" height="400"> <param name="movie" value="flash_file.swf"/> <!--other parameters--> </object>

With the object element, parameters are listed using "param" tags. To stop automatic playing, you can include the "play" parameter inside the object element:

<object width="500" height="400"> <param name="movie" value="flash_file.swf"/> <param name="play" value="false"/> </object>

The "param" element with "play" as its name attribute lists the parameter using a name value pair.

3 JavaScript

Many websites use JavaScript code libraries such as SWFObject to write Flash content into HTML pages. The syntax used with these libraries varies, but generally allows you to control autoplay. The following example demonstrates using SWFObject:

var swfObj = new SWFObject("flash_file.swf", "swfmovie", "500", "400", "8", "#FFFFFF"); //set other properties swfObj.write("swfmovie");

To set the autoplay property, you can extend the sample code as follows:

var swfObj = new SWFObject("flash_file.swf", "swfmovie", "500", "400", "8", "#FFFFFF"); swfObj.addVariable("autostart ","false"); swfObj.write("swfmovie");

The "autostart" variable sets autoplay to false.

4 Flash Content

Although the syntax you use in HTML and JavaScript can determine whether or not an SWF movie automatically plays, this affects only the main timeline of the movie. In a Flash file, you can include movie clip symbols within the main timeline. Each movie clip is an object with its own timeline. If a movie clip is included on the main timeline, it will automatically play even if the SWF movie as a whole has been set to not autoplay in HTML or JavaScript. To stop autoplay in this situation, you need to edit the source FLA file used to generate the SWF, adding a "stop" function on the first frame of each timeline you want to stop automatically playing.

Sue Smith started writing in 2000. She has produced tutorials for companies including Apex Computer Training Software and articles on computing topics for various websites. Smith has a Master of Arts in English language and literature, as well as a Master of Science in information technology, both from the University of Glasgow.

×