troubleshooting Question

How do I transmit data from Javascript to Flash

Avatar of magman5
magman5Flag for Australia asked on
HTMLJavaScriptAdobe Flash
1 Comment1 Solution581 ViewsLast Modified:
I have used code from online resources and can successfully transfer information from Flash to Javascript. For some reason I am unable to call Flash functions from javascript.

The flash file is compiled using Actionscript 3.0 and Flashplayer 9. I am using Firefox 4.0.1 and Firebug 1.7.0 to debug javascript.

When I click the link to send data to flash, I get the Firebug error message:
flashmovie.sendTextFromHtml is not a function

Open in new window


My Flash code is:
import flash.external.ExternalInterface; 
import flash.events.Event; 
function getTextFromJavaScript(str:String):void 
{  
   received_ti.text = "From JavaScript: " + str; 
} 
ExternalInterface.addCallback("sendTextToFlash", getTextFromJavaScript); 
function clickSend(event:Event):void 
{  
   var jsArgument:String = sending_ti.text;  
   var result:Object = ExternalInterface.call("getTextFromFlash", jsArgument);  
   received_ti.text = "Returned: " + result; 
} 
send_button.addEventListener("click", clickSend); 

Open in new window


My Javascript code is:
function getFlashMovie(movieName) 
{
   var isIE = navigator.appName.indexOf("Microsoft") != -1;
   return (isIE) ? window[movieName] : document[movieName];  
}
function formSend(txt) 
{   
   flashmovie = getFlashMovie("swf/compass");
   flashmovie.sendTextFromHtml(txt); 
   console.log("sendTextFromHtml("+txt+")");
}

function getTextFromFlash(str) 
{   
   console.log("getTextFromFlash(" + str+")");
   return str + " received";  
}

Open in new window


The flash file is embedded into html as follows:
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="260" height="280" id="swf/compass" align="middle">
<param name="movie" value="swf/compass.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<param name="play" value="true" />
<param name="loop" value="true" />
<param name="wmode" value="transparent" />
<param name="scale" value="showall" />
<param name="menu" value="true" />

<param name="devicefont" value="false" />
<param name="salign" value="" />
<param name="allowScriptAccess" value="always" />
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="swf/compass.swf" width="260" height="280">
<param name="movie" value="swf/compass.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<param name="play" value="true" />

<param name="loop" value="true" />
<param name="wmode" value="transparent" />
<param name="scale" value="showall" />
<param name="menu" value="true" />
<param name="devicefont" value="false" />
<param name="salign" value="" />
<param name="allowScriptAccess" value="always" />
<!--<![endif]-->
<a href="http://www.adobe.com/go/getflash">

<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
</a>
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object>

Open in new window


Does anyone have a clue why my "sendTextFromHtml" function cannot be found by javascript?
ASKER CERTIFIED SOLUTION
magman5

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros