Data Communication between JavaScript and Adobe Flash Movie
Passing data to Adobe Flash Movie using JavaScript
In Web2.0 arena we frequently use Adobe Flash Movie and JavaScript in our web page. We often has the requirement to pass data to the Adobe Flash movie at runtime. This can be achieve through communication between JavaScript and adobe flash swf move. “setVariable” is a method available in javascript that is responsible for passing data from JavaScript to Adobe Flash SWF movie.
Syntax:
SwfMovieName.setVariable(variable name,data to be send);
Note on using setVariable:
- setVariable requires an variable name. So a variable needs to be defined in adobe flash movie and the name of that variable is passed to the setVariable method
HTML Code:
<html>
<head>
<script LANGUAGE="JavaScript">
function changetext(str)
{
if(window.flashmovie)
window.document["flashmovie"].SetVariable("i", str);
if(document.sample)
document.flashmovie.SetVariable("i", str);
}
</script>
</head>
<body>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="" ID="flashmovie" WIDTH=400 HEIGHT=80>
<param NAME="movie" VALUE="sample.swf">
<embed play="false" swliveconnect="true" name="flashmovie" src="sample.swf" quality="high" bgcolor="#FFFFFF" WIDTH=400 HEIGHT=80 TYPE="application/x-shockwave-flash"></embed>
</param></object>
<form>
<p><input type="button" name="One" value="hello" onclick="changetext('hello')"/></p>
</form>
</body>
</html>Explanation:
- Here i have defined an function changetext inside JavaScript which will pass the data(function argument) to the flash swf movie
- window object refers to Mozilla Firefox and Opera browsers. Whereas document object refers to the Microsoft Internet Explorer browser so i am checking for the flash movie object reference through if conditions
- Finally i am calling the setVariable method to pass the data to the flash movie
Action Script Code
var i = ""; var j = setInterval(checki,10); function checki() { if(i != "") { myText = i + "123"; clearInterval(j); } }
Here I have set an interval that will check whether variable i has received any data. As soon as i receives any data it clears the interval and assigns the data to myText. Where myText is the Variable name of the dynamic textbox.
Similar Posts
Did you enjoy this post? Why not leave a comment below and continue the conversation, or subscribe to my feed and get articles like this delivered automatically to your feed reader.


Comments
No comments yet.
Leave a comment