June 3, 2001 - Replacing a Movie on the Fly | WebReference

June 3, 2001 - Replacing a Movie on the Fly

Yehuda Shiran June 3, 2001
Replacing a Movie on the Fly
Tips: June 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

In some of your applications you may need to use Flash movies and JavaScript directly, without any prepackaged APIs such as the FlashSound JavaScript API. You will enjoy more features, methods, and properties, but you'll have to take care of all the tiny details that are taken for granted when using the FlashSound API, for example.

One of those "tiny" details is embedding the Flash object. The JavaScript file flashmoviecheck.js does exactly this, as well as other stuff. For example, it checks whether a Flash player exists (Flash plug-in or ActiveX control), and whether its version is higher than the minimum required by the application.

Use the Flash method LoadMovie() to load a SWF file. The syntax is:

  LoadMovie(layerNumber, URL)
This method loads a given SWF (2nd argument) into the SWF object that the method belongs to. The parameter layerNumber designates the position of the new SWF with respect to other SWFs in the same page area. Set layerNumber to zero to ensure that any old SWFs are deleted before the new SWF is loaded.

In this tip we preload swift3d.swf. You can see its traces in the window below. When you click the Load Movie link, another SWF, opener.swf (courtesy of www.associatesinscience.com), will be loaded instead of the previous SWF. Use the following links to play, rewind, and load opener.swf:

Rewind | Play | Load Movie

Here is the code:


<SCRIPT LANGUAGE="JavaScript" SRC="flashmoviecheck.js"></SCRIPT>
<A href="javascript://" 
   onclick="javascript:mySwf.Rewind(); 
   return false">Rewind</A> | 
<A href="javascript://" 
   onclick="javascript:mySwf.Play(); 
   return false">Play</A> | 
<A href="javascript://" 
   onclick="javascript:mySwf.LoadMovie(0, 'opener.swf'); 
   return false">Load Movie</A>
<SCRIPT LANGUAGE="JavaScript">
  Flash_embedSWF("swift3d.swf");
  var mySwf = window.document.sonify;
</SCRIPT>