Custom Search

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:

  • Also name attribute for the tag and tag is required to access the adobe flash movie object in javascript




  • 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:

    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

    (required)

    (required)