Guest User

Untitled

a guest
Jan 22nd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. package lib
  2. {
  3. /**
  4. * Note: This is not optimized just sample code
  5. */
  6. public Class CrossDomainImageDownloader
  7. {
  8. public static function getImage(url:String, callback:Function):void
  9. {
  10. //download cross-domain image
  11. var loader:Loader = new Loader();
  12. loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function (event:Event):void
  13. {
  14. //pipe the byteArray from the image to a new loader
  15. var loader:Loader = new Loader();
  16. loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event):void
  17. {
  18. //The bytes that have been transformed into an image with no domain restrictions
  19. var pic = LoaderInfo(e.target).content;
  20. if(pic is flash.display.MovieClip) {
  21. var b:BitmapData = new BitmapData(pic.width, pic.height, true, 0x000000);
  22. b.draw(pic);
  23. pic = new Bitmap(b);
  24. }
  25. //send the image to the callback function
  26. callback(pic);
  27. });
  28.  
  29. loader.loadBytes(event.target.bytes);
  30. });
  31.  
  32. loader.load(new URLRequest(url));
  33. }
  34. }
  35. }
Add Comment
Please, Sign In to add comment