Simplyprofound.com
Flash, Flex, AIR, ASP.NET, PHP, AJAX, whatever it takes...

Flex Debugging - SecurityError #2060

April 1, 2008 17:18 by dave

I was wiring up an ExternalInterface call from my Flex application to javascript function in my HTML page today. It's really easy. But darn it if I could get the thing to work when debugging or running from Flex Builder. I kept getting the error:

SecurityError #2060: Security sandbox violation: ExternalInterface caller... (blah/blah/mxml cannot talk to blah/blah/html)

I was also getting an error in my javascript function which drew my attention. I was calling document.getElementById('myDiv').innterHTML and getting the error that my element "has no properties". Now, that's not a tough bit of code, so what was the deal? I was calling the function before the element was actually available in the page...it didn't exist yet. To verify this I put the function call inside of a window.onload function and viola, it worked.

So, back to the security error. I searched high and low and found dozens of 0 reply posts (there has to be a name for those poor souls left adandoned and alone - I think I'm the author of most of them!) where developers lamented the issue. 

The common situation: it works on the web server, but throws this error when running/debugging locally.

Flex Builder launches the application in your browser, and throws localhost on the front of the path which sounds like it's running in a virtual web server. It's not. Notice file://localhost. That means it's just reading the file locally, hence the security exception. 

It seemse to me that the only reasonable solution is to run a local web server and launch the Flex application to the local web path rather than the file path. Then your browser would be looking at http://localhost instead and the security issue would go away. 

To accomplish this setup your web server run a website from the bin-debug folder, then in Flex Builder modify your run/debug dialogue to open http://localhost/nameOfMyApp/myFile.html instead of the filepath that is there now.


Tags: ,
Categories: Flex
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Related posts

Add comment


(Will show your Gravatar icon)  

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]