June 12, 2001 - Embedding Multiple Flash Objects | WebReference

June 12, 2001 - Embedding Multiple Flash Objects

Yehuda Shiran June 11, 2001
Embedding Multiple Flash Objects
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 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 FlashSound API, for example.

One of the "tiny" details is embedding the Flash object. The JavaScript file flashcheck2.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.

You embed a Flash object according to the following two-line example:

<SCRIPT LANGUAGE="JavaScript">
  Flash_embedSWF("opener.swf", "opener");
  var mySwf = window.document.opener;
</SCRIPT>

Here is another example:

<SCRIPT LANGUAGE="JavaScript">
  Flash_embedSWF("swift3d.swf", "sonify");
  var mySwf = window.document.sonify;
</SCRIPT>

Here are two SWFs loaded on the same page. Play around with both links:

Rewind | Play | Zoom In by 2x | Zoom Out by 2x | Zoom to Area

Rewind | Play | Zoom In by 2x | Zoom Out by 2x | Zoom to Area

Here is the source code:

<SCRIPT LANGUAGE="JavaScript" SRC="flashcheck2.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.Zoom(50); return false">Zoom In by 2x</A> | 
<A href="javascript://" onclick="javascript:mySwf.Zoom(200); return false">Zoom Out by 2x</A> | 
<A href="javascript://" onclick="javascript:mySwf.SetZoomRect(0, 400, 1480, 1240); return false">Zoom to Area</A>
<SCRIPT LANGUAGE="JavaScript">
  Flash_embedSWF("swift3d.swf", "sonify");
  var mySwf = window.document.sonify;
</SCRIPT>
<A href="javascript://" onclick="javascript:mySwf2.Rewind(); return false">Rewind</A> | 
<A href="javascript://" onclick="javascript:mySwf2.Play(); return false">Play</A> | 
<A href="javascript://" onclick="javascript:mySwf2.Zoom(50); return false">Zoom In by 2x</A> | 
<A href="javascript://" onclick="javascript:mySwf2.Zoom(200); return false">Zoom Out by 2x</A> | 
<A href="javascript://" onclick="javascript:mySwf2.SetZoomRect(0, 400, 1480, 1240); return false">Zoom to Area</A>
<SCRIPT LANGUAGE="JavaScript">
  Flash_embedSWF("opener.swf", "opener");
  var mySwf2 = window.document.opener;
</SCRIPT>