| Calling a flash movie's
methods from javascript is very simple. There is a list
of flash methods callable from javascript, please refer
to Macromedia
Flash Support Center for the complete list. In this
tutorial, we will demonstrate some of them (SetVariable,
Play
& StopPlay, ...etc).
Example 1 - SetVariable
This exmple demonstrate calling the Flash
method "SetVariable" from javascript. It assumed
that you have a simple flash movie with a piece of text
(variable name: "mytext") on it. For details
on how to create the flash movie, please take a look
at our other
tutorial.
Click the following buttons to set / change the text
in the movie.
Step 1
First of all we need to insert the flash movie into
a HTML page. Then assign an id to the flash object in
the html code. Put the following parameter into the
corresponding <OBJECT> tag:
And put the following parameters into the <EMBED>
tag (this seems not necessary on my own settings: IE6,
Win XP, Flash Player 6, but may be requried on other
platforms):
name="dyn_text" swLiveConnect=true
|
By setting the aboves, it allow javascripts to access
the movie clip using the id / name "dyn_text".
Step 2
Then we implement a simple javascript function for
changing the text in the movie:
| <script language="JavaScript">
<!-- no script
function changetext(str)
{
document.getElementById( "dyn_text"
).setVariable( "mytext", str);
}
-->
</script>
|
Basically, this function will change the text in the
movie to whatever the input parameter (str) is.
Step 3
Finally, we need to add the code to the buttons, so
they will call the javascript function when being clicked:
onclick="changetext('somthing')"
|
(note: you need to look for the HTML code for both
buttons, and put the above inside the corresponding
<input> tag. Change 'something' to whatever you
like.)
< Tutorials
Index - Download
this tutorial - Post
suggestions >
|