↑
Main Page
JavaScript-to-Flash communication
JavaScript-to-Flash communication
Flash movies provide a number of standard methods that can be accessed by JavaScript:
?
GetVariable(variable_name)
— Retrieves the value of a Flash movie variable
?
GotoFrame(frame_number)
— Sets the current Flash frame to the given frame number
?
IsPlaying()
— Indicates whether the Flash movie is current playing
?
LoadMovie(layer_num, url)
— Loads a Flash movie at the given URL into the given Flash
layer
?
Pan(x, y, mode)
— Pans a zoomed movie to the given coordinate. The mode argument is either
0, to consider the coordinates as pixel values, or 1, to consider the coordinates as percentages.
?
PercentLoaded()
— Returns the percent of the Flash movie that has been loaded (a number 0
to 100)
?
Play()
— Plays the movie from the current position
?
Rewind()
— Sets the movie back to the first frame
?
SetVariable(variable_name, value)
— Sets the value of a Flash movie variable
?
SetZoomRect(left, top, right, bottom)
— Sets the rectangle to zoom in on
?
StopPlay()
— Stops the Flash movie
?
TotalFrames()
— Returns the total number of frames in the Flash movie
?
Zoom(percent)
— Zooms in by a given percentage
These methods work directly on the movie object itself, so to stop a movie named
ExampleMovie
, you can
do this:
var oFlashMovie = getFlashMovie(“ExampleMovie”);
oFlashMovie.StopPlay();
To get the total number of frames in the movie, use
TotalFrames()
. However, you must be aware of
some cross-browser compatibility issues. In Internet Explorer on Windows, there is a bug where
TotalFrames
is an integer value instead of a function. It is necessary to check for this using
typeof
to
determine if
TotalFrames
is a number or a function for cross-browser functionality:
function getTotalFrames(sName) {
var oFlashMovie = document.getElementById(sName);
if (typeof oFlashMovie == “function”) {
return oFlashMovie.TotalFrames();
} else {
return oFlashMovie.TotalFrames;
}
}
553
Interacting with Plugins
21_579088 ch18.qxd 3/28/05 11:43 AM Page 553
Free JavaScript Editor
Ajax Editor
©
→