Home > Adobe, Programming > Data Communication between JavaScript and Adobe Flash Movie

Data Communication between JavaScript and Adobe Flash Movie

Posted by Hitesh Agrawal

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<!-- google_ad_client = "pub-9693430925007646"; /* 468x60, created 24/01/08 */ google_ad_slot = "2845771628"; google_ad_width = 468; google_ad_height = 60;
  • 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.

    Categories: Adobe, Programming
    1. No comments yet.
    1. No trackbacks yet.

    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com 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

    %d bloggers like this: