Main Page

Embedding Flash movies

Embedding Flash movies
To embed a Flash movie into an HTML page, use the
<object/>
element:
<object type=”application/x-shockwave-flash” data=”myflashmovie.swf”
width=”100” height=”100” id=”FlashMovie”></object>
Mozilla-based browsers won’t display this properly, so you need to add a
movie
parameter set to the
same URL as the
data
attribute:
<object type=”application/x-shockwave-flash” data=”myflashmovie.swf”
width=”100” height=”100” id=”FlashMovie”>
<param name=”movie” value=”myflashmovie.swf” />
</object>
Of course, if you want to support Netscape 4.x, include the
<embed/>
element:
<object type=”application/x-shockwave-flash” data=”myflashmovie.swf”
width=”100” height=”100” id=”FlashMovie”>
<param name=”movie” value=”myflashmovie.swf” />
<embed type=”application/x-shockwave-flash” src=”myflashmovie.swf”
width=”100” height=”100” quality=”high” name=”FlashMovie”>
</embed>
</object>
Referencing Flash movies
Just like Java applets, Flash movies can be referenced in a couple of different ways depending on how
you embed them (using
document.getElementById()
for
<object/>
or
document.embeds
for
<embed/>
). The following function can be used to retrieve a reference to a Flash movie regardless of the
embedding process used:
function getFlashMove(sName) {
if (document.getElementById) {
return document.getElementById(sName);
} else {
return document.embeds[sName];
}
}
This function can be called like so:
var oFlashMovie = getFlashMovie(“FlashMovie”);
After you have a reference to the movie, it’s possible to communicate back and forth using JavaScript.
552
Chapter 18
21_579088 ch18.qxd 3/28/05 11:43 AM Page 552


JavaScript EditorFree JavaScript Editor     Ajax Editor


©