Posted By

Winkyboy on 06/15/09


Tagged

preloader photo loader as3 bitmap smoothing circular spinning


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

liamr
pauloc
TrentSkunk
davidino1978
tspitzr


AS3 Image Loader with circular preloader spinner


 / Published in: ActionScript 3
 

URL: http://dl.dropbox.com/u/316550/code-AS3-imgLoder.zip

Not a really elegant design, but it lets you mess around with the loading code easily.

  1. import caurina.transitions.Tweener; // don't forget to install this.
  2.  
  3. function loadImageTo(which_mc:MovieClip, whichImg:String, finishFunction:Function):void // syntax: loadImageTo("which movieclip to add the image to", "the path/URL to the image", "the function to call when complete")
  4. {
  5. var imageLoader:Loader = new Loader();
  6. imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, finishFunction);
  7. which_mc.addChild(imageLoader);
  8. try {
  9. imageLoader.load(new URLRequest(whichImg));
  10. } catch (error:IOErrorEvent) {
  11. // ouch! an error
  12. } catch (error:Error) {
  13. // ouch! an error
  14. }
  15. }
  16.  
  17. function hideSpinner1(e):void // you should totally customize this function
  18. {
  19. Tweener.addTween(spinner_mc, {alpha:0, time:.5, onComplete:function(){ spinner_mc.enabled = false; } }); // keep this line in here, to hide the spinner.
  20.  
  21. // resize your new image:
  22. holder_mc.width = stage.stageWidth;
  23. holder_mc.height = stage.stageHeight;
  24.  
  25. // apply smoothing to your new image:
  26. var img_bm:Bitmap = new Bitmap();
  27. img_bm = Bitmap(e.currentTarget.content);
  28. img_bm.smoothing = true;
  29. }
  30.  
  31. function init()
  32. {
  33. if (holder_mc.numChildren > 0) holder_mc.removeChildAt(0); // this line is added so that any previously-loaded image is removed before adding another to the holder
  34. loadImageTo(holder_mc, "sample.jpg", hideSpinner1); // if you want to use the loadImageTo function without a preloader spinner, just create an empty function and send that as the "finishFunction"
  35. }
  36.  
  37. init(); // make it so.

Report this snippet  

You need to login to post a comment.