Skip to content

Instantly share code, notes, and snippets.

@puppybits
Created September 8, 2011 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save puppybits/1204895 to your computer and use it in GitHub Desktop.
Save puppybits/1204895 to your computer and use it in GitHub Desktop.
Hack for Flash's security policy for cross-domain editable images
package lib
{
/**
* Note: This is not optimized just sample code
*/
public Class CrossDomainImageDownloader
{
public static function getImage(url:String, callback:Function):void
{
//download cross-domain image
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function (event:Event):void
{
//pipe the byteArray from the image to a new loader
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event):void
{
//The bytes that have been transformed into an image with no domain restrictions
var pic = LoaderInfo(e.target).content;
if(pic is flash.display.MovieClip) {
var b:BitmapData = new BitmapData(pic.width, pic.height, true, 0x000000);
b.draw(pic);
pic = new Bitmap(b);
}
//send the image to the callback function
callback(pic);
});
loader.loadBytes(event.target.bytes);
});
loader.load(new URLRequest(url));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment