Sudheer and some guys from IITB were building some UI in Flex. They had a case where they were getting some photos from a server in another domain and then giving it to the DisplayShelf component by Ely to display in a cool UI. But when they tried to flip through the pictures using the interface, it threw an error as below.
SecurityError: Error #2122: Security sandbox violation: BitmapData.draw: http://<Server Name>/<App Name>.swf cannot access http://<image path>.jpg. A policy file is required, but the checkPolicyFile flag was not set when this media was loaded.
As the above error says, the operation is trying to read the bitmap data of the image using the flash.display::BitmapData/draw() method and this is allowed only in 2 cases…
- When you have a policy file on the cross-domain server which allows you full access
- When the content is in the same domain
You may not be able to do (1) since the server you are getting data from may not belong to you. The other alternative is to have the image on your server (or same domain) which is where proxy-ing comes in. So you have to write a server code to proxy the data (in this case image) onto your server and then access it. Here’s the JSP script that lets you do it. If you are a PHP guy you can take this script that Abdul has written.
How to use it?
You need to pass the source of your image as below:
img.source = “testProxy1.jsp? url= http://www.theflexshow.com/blog/images/ the_flex_show.jpg &mimeType= image/jpg”;
As you see, you need to pass 2 GET variables, which are url & mimeType. Click here if you don’t know the mime type of your content. Here is an example mxml code to test the above script. I’m using Distortion Effects by Alex Uhlmann in this example. So be sure to compile the source code with the SWC (check this post if you don’t know how to compile in an external swc into your app).
Also, feel free to edit the script/code and use it at your will… Hope this helps