The other day I received one of these types of queries, but with a twist; they wanted me to use my client application against their server. Oddly enough this had never come up before, so I set out to get this working. Oddly enough it took me a bit of searching before I found the solution, considering the end result was so simple. Going forward I will refer to my machine as Machine A (client) and my coworkers machine as Machine B (server). So if you jumped right in and tried to point your client right at Machine B you would get this error, SecurityError: Error #2123: Security sandbox violation, because Flash is not happy about trying to access a server on a different machine. However you can set up a cross domain file to allow this type of access.
- Create a new xml file named crossdomain.xml on Machine A.
- Download my sample cross domain file sample-crossdomain.xml (note these values allow any domain to access your server so you should fine tune it for your case if in a production environment).
- Change the name to crossdomain.xml
- Send the crossdomain.xml file to the person using Machine B.
- On Machine B place the crossdomain.xml into the ROOT folder of the app server, so you can go to http://MACHINEB/crossdomain.xml and see the file from Machine B.
- Open up the main application mxml file of your Flex application.
- Add an initialization event handler to the application if one doesn't already exist.
- Add this line to the initialization handler: Security.loadPolicyFile("http://MachineB/crossdomain.xml");
- Finally wherever you have defined the URL for your AMF channel needs to be updated to point to Machine B.
Additional Resources
No comments:
Post a Comment