public
Last active

Hack for Flash's security policy for cross-domain editable images

  • Download Gist
CrossDomainImageDownloader.as
ActionScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
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));
}
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.