Created
September 8, 2011 22:01
-
-
Save puppybits/1204895 to your computer and use it in GitHub Desktop.
Hack for Flash's security policy for cross-domain editable images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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