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.
  • Advertisements

    About Saran

    Hello there!!! I'm Saravanan, born and living in India. The main reason i decided to start this project it was because there should be a way to transfer my knowledge which i experimented in flash to all. i try to concentrate as much as possible all kind of issues can appear to someone is developing an Flash application. If you need help, or if you would like to see in this blog some issues, send me an e-mail to Follow Me: twitter: Best Regards, SRK
    This entry was posted in Flash. Bookmark the permalink.

    Leave a Reply

    Please log in using one of these methods to post your comment: Logo

    You are commenting using your account. Log Out /  Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out /  Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out /  Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out /  Change )

    Connecting to %s