Problem with Flash ExternalInterface in Google App Engine

I have been struggling with this for the past two hours, and I really don't know what could be wrong. I'm just trying to get Javascript to pass text using Flash. I found this great example with this source.

http://blog.circlecube.com/wp-content/uploads/2008/02/ActionscriptJavascriptCommunication.zip

I ran the html file locally and it just perfectly transfers and extracts text from a flash drive. Then I upload the exact same sample to my Google application dev server and I cannot send text from javascript to flash. Oddly enough, though flash can send Javascript text. Can anyone see if they can work with GAE? Thanks a million!

+2
source share
3 answers

I do not see the allowDomain function call in your code. Due to the fact that the isolated security software environment does not allow your flash application to interact with the flash and vice versa on the server. Add a call to System.security.allowDomain("mydomain.com", "mySecondDomain.com", "etc.com") for each domain in which the flash application will run. In addition, the embed code should also indicate JavaScript access, including the <param name="allowScriptAccess" value="always" /> parameter.

+1
source

This is probably not related to the Google engine for Google, since everything that works in the browser is if there is no dependency on a server that you did not mention. Assuming no case ...

If you can get Flash to call JavaScript using ExternalInterface.call () but not JavaScript to call Flash back, then this is probably one or two things: your EI callback and the handler are not properly connected (in Flash), or your JavaScript does not have a SWF object handle in the browser.

You might be trying to post some kind of code, but in the meantime, something that I know works in both IE and FireFox. Firstly, 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, this is Flex, so hopefully this is 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> 

This example demonstrates a Flash call in JavaScript with some text, and a JavaScript call back to Flash in a similar way. Some points to pay attention to:

  • Make sure you expect to trigger the Flash until Flash informs the browser that it is ready to receive calls (as indicated by my callbacksInitialized ()).
  • Test to make sure that you are using the appropriate browser-specific link object (for example, the ["HelloMac"] vs. document ["HelloMac"] window).

Without knowing anymore, I assume that this is one of these two subjects, as it was my experience. Hope it helps! I will follow up on the follow-up message, if you have any.

+2
source

Answer from Christian Nunciato is helpful. The problem is that your swf file is not available for javascript while your javascript is calling the flash function. A Christian trick ensures that the swf file loads and runs when you need javascript.

0
source

All Articles