Jun

17


Embedded Flash Movie in HTML document can be manipulated by using JavaScript. There are default build-in JavaScript functions that can be used to communicate with Flash. But there is one function which is doesn’t come by default but requested by many - the replay function. There are times you may want to instruct Flash to replay the movie using a JavaScript function, this can be easily done if we combine two build-in functions: play() and rewind(). Assume that you have the Flash movie code like the one below:

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="560" height="404" id="coreMovie" align="middle">
<param name="allowScriptAccess" value="sameDomain" /><param name="wmode" value="transparent" />
<param name="movie" value="files/core.swf'" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="files/core.swf" quality="high" bgcolor="#ffffff" width="560" height="404" name="coreMovie" align="middle" wmode="transparent"  allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>

Two attributes from the above standard code are important: the id attribute within tag and the name attribute under tag. The value of these two attributes should be the same and it acts as the reference when communicate with JavaScript. The JavaScript below controls the movie above.

function getFlashMovieObject(movieName) {
	if (window.document[movieName]) {
		return window.document[movieName];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1) {
		if (document.embeds &amp;amp;amp;&amp;amp;amp; document.embeds[movieName]) {
			return document.embeds[movieName];
		}
	} else {
		return document.getElementById(movieName);
	}
}
function ReplayFlashMovie(mname) {
	var flashMovie=getFlashMovieObject(mname);
	flashMovie.Rewind();
	flashMovie.Play();
}
ReplayFlashMovie('coreMovie');


Similar Posts

Comments

Name (required)

Email (required)

Website

Speak your mind

Sponsors




Links