JavaScript

Using JavaScript with Shockwave Flash Player

Basics

There are two basic actions that can be performed with Flash scripting.

  1. Control Shockwave Flash using a method such as Play(), or CurrentFrame().
  2. Send a message from a Flash button or frame action to JavaScript code in your web page with FSCommand.

There are two basic actions that can be performed with Flash scripting. The first type of action is to control Shockwave Flash using a method such as Play(), GotoFrame(), or CurrentFrame(). The second type of action is to send a message from a Flash button or frame action to JavaScript code in your web page with FSCommand. More details are provided below.

JavaScript Methods in Flash

There are 1- methods made available to you by the Shockwave Flash player.

These methods are not available until after the plugin is loaded by the browser. If you try to control a plugin with any of these methods before it is loaded, error messages will be displayed. This is because the script is attempting to use a method that is available from the plugin, but no instance of the plugin exists.  To avoid this problem, have your Flash movie send an FSCommand event using the Get URL action applied to frame 1 in the movie.  When the plugin and the movie load, the event will be passed to your script and you may then make a function call to execute a method.

  • Play() - Start playing the animation.
  • StopPlay() - Stop playing the animation.
  • IsPlaying() - Returns true if the movie is currently playing.
  • GotoFrame (int frameNum) - Goto a specific frame of the movie.
  • TotalFrames() - Returns the total number of frames in the movie.
  • Rewind() - Go back to the first frame.
  • SetZoomRect (int left, int top, int right, int bottom) - Zoom in on a rectangular area of the movie. Note that the units of the coordinates are in twips (1440 units per inch).
  • Zoom(int percent) - Zoom the view by a relative scale factor. Zoom(50) will double the size of the objects in the view. Zoom(200) will reduce the size of objects in the view by one half. Zoom(0) resets the view to 100%.
  • Pan (int x, int y, int mode) - Pan a zoomed in movie. The mode can be:
    • 0 = pixels
    • 1 = % of window.
  • PercentLoaded() - Returns the percent of the SwF file that has streamed in to the browser so far ranges (0-100).

To call methods in a Shockwave Flash movie, your EMBED and OBJECT tags must include a NAME/ID.  Also, the "#version=2,0,0,11" ensures that the proper version of the ActiveX control is installed

Here is an example of calling methods from JavaScript. The statements below should be a part of the function that is called from the NAME/ID_doFSCommand() function.

This code snippet accesses the loaded Shockwave Flash and rewinds the movie to the beginning and them resets any zoom settings back to normal.  Notice the casual but powerful browser detect in the script. 

More info at: http://www.macromedia.com/support/flash/



Kathie Kingsley-Hughes
Last updated: May 4th 2004
Print This Page   |   Email me when this page changes    |  Search This Site



Crucial.com System Scanner does the work for you!



udes/a_global/close_links.inc"); ?>

Contact Us