views:

26

answers:

1

I have a java server (that now runs locally) to which my flash app will connect. Although it connects just fine when i run from CS4, when i exported the app and use XAMPP to access the flash app from the browser i get an error:

{NetworkManager}: (Security Error) [SecurityErrorEvent type="securityError" bubbles=false cancelable=false eventPhase=2 text="Error #2048"]

what can i do to establish the connection either i run the app from CS4 or by accessing the published on from a browser?

+1  A: 

If you're talking about an HTTP connection on port 80 then you need to the target serve to provide a cross-domain policy file.

http://www.adobe.com/devnet/flashplayer/articles/cross_domain_policy.html

When an attempt is made to load content into a SWF file at runtime, the request is subject to the Flash Player security model, which is in place to protect users and website owners. As part of this model, Flash Player by default prevents cross-domain loading of data, but allows cross-domain sending of data.

<!-- crossdomain.xml in root -->
<cross-domain-policy> 
    <allow-access-from domain="*" /> 
</cross-domain-policy> 

If you're talking about a socket connection on another port, then to setup a socket policy server to provide a policy file on a specific port. It needs to listen for connections on port 843 and then serve up a policy file which specifies which domains are allowed access to which local ports.

<cross-domain-policy>  
    <allow-access-from domain="swf.example.com" to-ports="123,456-458" /> 
</cross-domain-policy> 

There are free options for hosting a separate process to serve this file or you can implement it yourself within your current Java application.

http://www.adobeopenoptions.com/devnet/flashplayer/articles/socket_policy_files.html

Sam
I have setup the XAMPP to recognize the url http://mygames.local as localhost so every time i enter it on my browser i can fetch the files in a local directory, where the swf is. I have made a crossdomain.xml file as you said, and add the Security.loadPolicyfile("path/to/crossdomain.xml") into the constructor of the NetworkManager that does the connections (using sockets) with the server. But it doesn't work.
@user466825, you should add more details about exactly how the swf is communicating, exactly the content of your crossdomain.xml file, and how it's being served.
Sam
The swf file uses a socket to commicate with the server. It writes a string to the sockets and flushes it to the java server which responds with a string also, and that's all between them, then the swf closes the socket. The content of the crossdomain.xml file is like the second paradigm u gave but in the allow-access-from i have put the http://mygames.local and to-ports="12345" because that is the port that the server listens to.
@user466825, and have you confirmed that the policy file is being requested and served?
Sam
I type Security.loadPolicyfile("path to xml"). How can i see if the policy file is being requested and server? Do i have to alter the code on java server?
@user466825, you can't just call `Security.loadPolicyFile` to grant socket access. This used to work but has gradually been made stricter and stricter in many versions of 9.x and 10.x. At this point in order to make a socket connection from Flash you must serve a socket policy file from a socket server on port 843. Flash will automatically connect on this port and expect to receive the policy file.
Sam
i don't understand, what code do i have to add to achieve this? Is this only on the client (flash) side or do i have to change the server's code also? Can you tell what do i have to change exactly?Do i have to add port 843 on the crossdomain.xml?
You have to have the server listen on port 843 for a tcp connection. When it gets a connection on that port, it should respond with the cross domain file.
Sam