Posted By

xxneon on 03/19/08


Tagged


Versions (?)

Preload Slideshow


 / Published in: ActionScript
 

  1. var intID:Number;
  2. function preloadImages(src:Array) {
  3. var p:MovieClip = this.createEmptyMovieClip("p_mc", this.getNextHighestDepth());
  4. var mcl:MovieClipLoader = new MovieClipLoader();
  5. var listener:Object = {};
  6. mcl.addListener(listener);
  7. listener.onLoadComplete = function(target_mc:MovieClip) {
  8. p.loadedImages++;
  9. target_mc.removeMovieClip();
  10. };
  11. p._visible = false;
  12. p.totalImages = src.length;
  13. p.loadedImages = 0;
  14. for (var i = 0; i<src.length; i++) {
  15. p.createEmptyMovieClip("image"+i,i);
  16. mcl.loadClip(src[i].image,p["image"+i]);
  17. }
  18. intID = setInterval(this, "checkProgress", 30, p, mcl);
  19. }
  20. function checkProgress(pContainer:MovieClip, mcl:MovieClipLoader) {
  21. var percentage = 0;
  22. for (image in pContainer) {
  23. if (pContainer[image] instanceof MovieClip) {
  24. var progressObj:Object = mcl.getProgress(pContainer[image]);
  25. }
  26. if (progressObj.bytesLoaded>0) {
  27. percentage += progressObj.bytesLoaded/progressObj.bytesTotal;
  28. }
  29. }
  30. var totalPercentage = (percentage+pContainer.loadedImages)/pContainer.totalImages;
  31. if (totalPercentage>=1) {
  32. pContainer.removeMovieClip();
  33. clearInterval(intID);
  34. }
  35. updateBar(Math.round(totalPercentage*100));
  36. }
  37. function updateBar(percent:Number) {
  38. preloader._visible = true;
  39. preloader.preload_bar._xscale = percent;
  40. if (percent == 100) {
  41. preloader._visible = false;
  42. firstImage();
  43. }
  44. }

Report this snippet  

You need to login to post a comment.