Enabling BitmapData.draw (..) on crossdomain images in Adobe Flash Player 928 Jan 2007
Adobe Flash Player 8 and 9 have security-sandbox where-in you can not use BitmapData's draw (..) on crossdomain images, as I mentioned in one of my posts. There is no easy way of doing it with Flash Player 8, you need some kind of shim/library.swf or server-side proxy.
Fortunately, Adobe Flash Player 9 has some APIs (Loader, LoaderContext) to make life easier, provided you have a crossdomain.xml with right permission on the server hosting images.
Say "ServerA" has main application and "ServerB" hosts image files. You need to place crossdomain.xml in root of "ServerB". Just having crossdomain.xml is not sufficient, so you need to do something more:-
- Create a LoaderContext instance
- Set it's checkPolicyFile = true;
- Pass LoaderContext instance to Loader.load (..) method, as shown below. </ol>
Note: Following code shows the steps, it's not a working example.
var request:URLRequest = new URLRequest ();
request.url = "http://ServerB/images/foo.jpg";
//This is important step..
var loaderContext:LoaderContext = new LoaderContext ();
loaderContext.checkPolicyFile = true;
var loader:Loader = new Loader ();
loader.load (request, loaderContext);
//now you can draw.
var bitmapData:BitampData = new BitmapData (200, 200);
Why we need to this? Doing so would instruct Flash Player not to begin downloading the image file until after attempting to download a policy file. If Flash Player successfully finds policy file with right permission, you are set to do Bitmap drawing.
Believe me, that's all you need as long as you meet two criteria (crossdomain.xml and checkPolicyFile=true). I would try to post a working example.