Monday, November 25, 2013

Debug Flex Application Against Different Server Machine

Once in a while one of my server co-workers will ask me to test something on my current version of our client Flex application.  Generally they are asking me because they will use the same version of the client application as long as possible, which in some cases could be a couple weeks.  They also know that every morning I get a fresh copy of everything and always try to run the "latest greatest".

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.


  1. Create a new xml file named crossdomain.xml on Machine A.
  2. 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). 
  3. Change the name to crossdomain.xml
  4. Send the crossdomain.xml file to the person using Machine B.
  5. 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. 
  6. Open up the main application mxml file of your Flex application.
  7. Add an initialization event handler to the application if one doesn't already exist.
  8. Add this line to the initialization handler:  Security.loadPolicyFile("http://MachineB/crossdomain.xml");
  9. 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