I\'ve been struggling with this for the past couple hours now and I really don\'t know what could be wrong. I\'m simply trying to get Javascript to communicate text with Fla
It probably doesn't have to do with Google app engine per se, since the whole thing's running in the browser -- unless there's some sort of server dependency somewhere you haven't mentioned. Assuming that's not the case...
If you're able to get Flash to call into JavaScript with ExternalInterface.call(), but not JavaScript to call back into Flash, then it's probably one or two things: your EI callback & handler aren't wired up properly (in Flash), or your JavaScript doesn't have a handle on the SWF object in the browser.
You might try posting some code, but in the meantime, here's something I know works in both IE and FireFox. First, the browser code:
<html>
<head>
<script language="JavaScript" type="text/javascript">
var swfReady = false;
function callbacksInitialized()
{
swfReady = true;
}
function helloFlash()
{
if (swfReady)
{
// Get a handle on the Flash object
var swfObject = navigator.appName.indexOf("Microsoft") != -1 ? window["HelloMac"] : document["HelloMac"] ;
// Call back into the Flash file
swfObject.helloFlash(document.getElementById("txtMessage").value);
}
}
function helloMac(message)
{
alert(message);
}
</script>
</head>
<body scroll="no">
<div align="center">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
id="HelloMac" width="600" height="300"
codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
<param name="movie" value="HelloMac.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#869ca7" />
<param name="allowScriptAccess" value="sameDomain" />
<embed src="HelloMac.swf" quality="high" bgcolor="#869ca7"
width="600" height="300" name="HelloMac" align="middle"
play="true"
loop="false"
quality="high"
allowScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.adobe.com/go/getflashplayer">
</embed>
</object>
<br /><br />
<input type="text" id="txtMessage" value="Hello, Flash!" /><br />
<input id="btnSend" type="button" value="Send to Flash" onclick="helloFlash();" />
</div>
</body>
</html>
And now, the Flash code (in my case, it's Flex, so hopefully it's clear):
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="init()" height="300" width="600">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import flash.external.ExternalInterface;
private function init():void
{
addCallbacks();
}
private function addCallbacks():void
{
ExternalInterface.addCallback("helloFlash", this_helloFlash);
ExternalInterface.call("callbacksInitialized");
}
// Display a message from the host
private function this_helloFlash(message:String):void
{
Alert.show(message);
}
// Send a string to the host
private function helloMac():void
{
if (ExternalInterface.available)
{
ExternalInterface.call("helloMac", txtMessage.text);
}
}
]]>
</mx:Script>
<mx:VBox horizontalCenter="0" verticalCenter="0">
<mx:TextInput id="txtMessage" text="Hello, Mac!" />
<mx:Button id="btnSend" label="Send to Host" click="helloMac()" />
</mx:VBox>
</mx:Application>
The example demonstrates Flash calling into JavaScript with some text, and JavaScript calling back into Flash in the same way. Some points to pay attention to:
Without knowing more, I'm guessing it's one of these two items, since that's been my experience. Hope it helps! I'll keep an eye on the post for follow-ups in case you have any.
Yup the answer by Christian Nunciato is helpful. The issue is that your swf file is not available to javascript at the time your javascript calls the flash function. Christian's trick makes sure the swf file is loaded and started when your javascript needs it.
I do not see a call to the allowDomain function in your code. With out that the security sandbox will not allow your flash application to communicate with flash and vice versa on the server. Add a call to System.security.allowDomain("mydomain.com", "mySecondDomain.com", "etc.com")
for every domain the flash app will be executed on. Also the embed code also needs to specify access for JavaScript by including the parameter <param name="allowScriptAccess" value="always" />
.