Google analytics code

Friday, August 3, 2012

Flex / ActionScript 3 : Problem with ExternalInterface.addCallback

I'm adding some functionality to an existing Flex project that requires cross talk between ActionScript and Javascript. Reaching from ActionScript to Javascript is pretty easy. This can be done with the Calling from Javascript to ActionScript was a little tricker. Especially with local development.

You can use ExternalInterface.addCallback to create a bridge for Javascript to talk with ActionScript. There are a few more steps to make sure this is set up properly.

1) Make sure the id and name are the same in each AC_FL_RunContent function. Just changing one won't work. This way document.getElementById should always find the object on the page.
2) Make sure allowScriptAccess is set to always in each AC_FL_RunContent function. This updates the security setting so Javascript can access the Flash object.
3) If you're doing local development make sure to check Always allow in Global Security Settings Panel.

I found step 3 after wasting an entire morning looking around the internet. Without this I kept getting this warning.

*** Security Sandbox Violation ***
SecurityDomain 'null' tried to access incompatible context 'file:///foo/bar/project.swf'

Once you're project is finished you might want to change this back. Not sure what thing on the web wants to break your computer.

1 comment:

  1. You saved my hours of searching over the Interent :) 3rd position is really crucial :) thx


If you found this page useful, or you have any feedback, please leave a comment.