I Have a problem where I occasionally (i.e. not always) see the below error popup from the Debug Flash Player after launching my app:
Error #2044: Unhandled securityError:. text=Error #2048: Security sandbox violation: http://example.com/myApp.swf cannot load data from localhost:4499.
at org.mydomain.mypackage::MyClassUsingSocket()
at MyMainApplicationClass$cinit()
at global$init()
at global$init()
at flash.system::ApplicationDomain/hasDefinition()
at mx.managers::SystemManager/getDefinitionByName()
at _MyMainApplicationClass_mx_managers_SystemManager/create()
at mx.managers::SystemManager/initializeTopLevelWindow()
at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::docFrameHandler()
I have some code in this app that tries to connect to localhost:4499
via a Socket
, and this error occurs when the socket server is not running and listening for the connections, which is to be expected. What I don't understand, however, is why Flash Player is complaining about unhandled securityErrors when I have try/catch blocks to catch the SecurityError
s when trying to connect the socket (as well as listeners for the SecurityErrorEvents
, which this error message doesn't seem to point to, though).
The constructor of the relevant class is below:
/**
* Constructor.
*/
public function MyClassUsingSocket(aHost:String = null, aPort:int = -1):void
{
super();
var hostToConnectTo:String = (aHost != null) ? aHost : DEFAULT_HOST;
var portToConnectTo:int = (aPort != -1) ? aPort : DEFAULT_PORT;
try
{
_out_socket = new Socket();
// note: the event handlers used below are private functions within the same class
_out_socket.addEventListener(Event.CONNECT, _socketConnectEventHandler, false,0,true);
_out_socket.addEventListener(IOErrorEvent.IO_ERROR, _socketIOErrorEventHandler, false,0,true);
_out_socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, _socketSecurityErrorEventHandler, false,0,true);
_out_socket.connect(hostToConnectTo, portToConnectTo);
}
catch(e:IOError)
{
enabled = false;
}
catch(e:SecurityError)
{
enabled = false;
}
}
Any ideas on why this might be occurring? What am I missing?