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.

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
  • Also name attribute for the tag and tag is required to access the adobe flash movie object in javascript.
  • HTML Code:
    <script LANGUAGE="JavaScript">
    	function changetext(str)
    			window.document["flashmovie"].SetVariable("i", str);
    			document.flashmovie.SetVariable("i", str);
    	<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>
    		<p><input type="button" name="One" value="hello" onclick="changetext('hello')"/></p>


    • 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";
    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.
  • Data Communication between JavaScript and Adobe Flash Movie