spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column85


Embedding Movies with Flash, Part I: Basic Methods

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

Playing a Flash Movie

In order to embed a Flash movie in your Web page, follow these two steps:

  • Include the JavaScript include file, flashmoviecheck.js, in your header section:

    <SCRIPT LANGUAGE="JavaScript" SRC="flashmoviecheck.js">
    </SCRIPT>

  • Call Flash_embed() with your SWF file as a parameter. For example:

    Flash_embedSWF("swift3d.swf");

In order to play a Flash movie in your Web page, you need to follow these two steps:

  • Create a JavaScript Flash object. We named the embedded Flash player "sonify", in both Internet Explorer and Netscape Navigator. Therefore, you must use this name when creating the Flash object. You can name the object itself as you wish. We picked the name mySwf:

    var mySwf = window.document.sonify;

  • Call one of the many Flash methods that we start covering in this column. Here are two examples:

    mySwf.Rewind();
    mySwf.Play();

We already used one of the Flash methods (rewind()) in flashmoviecheck.js. The Flash player does not obey our assignment of AUTOSTART to false and the Flash movie autostarted when embedding. We put the following line in flashmoviecheck.js to prevent the movie from autostarting:

window.document.sonify.Rewind();

We can embed a Flash movie and create a JavaScript Flash object in the same script:

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

Here are two links that demonstrate the above methods, Rewind() and Play(). The code is shown below the movie area. Play around with these links and see the impact on the following SWF, courtesy of www.swift3d.com. Notice that the Rewind() method rewinds the video but not the audio track:

Rewind | Play

Here is the code for implementing the above links and Flash movie playing:

<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>
<SCRIPT LANGUAGE="JavaScript">
  Flash_embedSWF("swift3d.swf");
  var mySwf = window.document.sonify;
</SCRIPT>

Next: How to jump to a certain frame

http://www.internet.com

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business


Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: June 4, 2001
Revised: June 4, 2001

URL: http://www.webreference.com/js/column85/3.html