Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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));
- }
- }
- }
Add Comment
Please, Sign In to add comment