Posted By

sk8rjess on 03/19/08


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

hicham975


slideshow


 / Published in: ActionScript
 

  1. function preloadImages(src)
  2. {
  3. var p = this.createEmptyMovieClip("p_mc", this.getNextHighestDepth());
  4. var _loc4 = new MovieClipLoader();
  5. var _loc5 = {};
  6. _loc4.addListener(_loc5);
  7. _loc5.onLoadComplete = function (target_mc)
  8. {
  9. ++p.loadedImages;
  10. target_mc.removeMovieClip();
  11. };
  12. p._visible = false;
  13. p.totalImages = src.length;
  14. p.loadedImages = 0;
  15. for (var _loc2 = 0; _loc2 < src.length; ++_loc2)
  16. {
  17. p.createEmptyMovieClip("image" + _loc2, _loc2);
  18. _loc4.loadClip(src[_loc2].image, p["image" + _loc2]);
  19. } // end of for
  20. intID = setInterval(this, "checkProgress", 50, p, _loc4);
  21. } // End of the function
  22. function checkProgress(pContainer, mcl)
  23. {
  24. var _loc3 = 0;
  25. for (image in pContainer)
  26. {
  27. if (pContainer[image] instanceof MovieClip)
  28. {
  29. var _loc1 = mcl.getProgress(pContainer[image]);
  30. } // end if
  31. if (_loc1.bytesLoaded > 0)
  32. {
  33. _loc3 = _loc3 + _loc1.bytesLoaded / _loc1.bytesTotal;
  34. } // end if
  35. } // end of for...in
  36. var _loc5 = (_loc3 + pContainer.loadedImages) / pContainer.totalImages;
  37. if (_loc5 >= 1)
  38. {
  39. pContainer.removeMovieClip();
  40. clearInterval(intID);
  41. } // end if
  42. updateBar(Math.round(_loc5 * 100));
  43. } // End of the function
  44. function updateBar(percent)
  45. {
  46. preloader._visible = true;
  47. preloader.preload_bar._xscale = percent;
  48. if (percent == 100)
  49. {
  50. preloader._visible = false;
  51. onEnterFrame = myFrameEnter;
  52. firstImage();
  53. } // end if
  54. } // End of the function
  55. var intID;
  56. this.onEnterFrame = function ()
  57. {
  58. if (percent == 100)
  59. {
  60. playing = true;
  61. }
  62. else
  63. {
  64. pos_txt.text = "loading";
  65. playing = false;
  66. } // end else if
  67. if (percent < 100)
  68. {
  69. pos_txt.text = "loading";
  70. playing = false;
  71. } // end if
  72. };
  73.  
  74.  
  75. //---------------------------------
  76. //---------------------------------
  77. //---------------------------------
  78.  
  79. function myFrameEnter() {
  80. var bLoaded:Number = picture.getBytesLoaded();
  81. var bTotal:Number = picture.getBytesTotal();
  82. if (bLoaded == bTotal && bLoaded>0) {
  83. picture._width = 763;
  84. picture._height = 525.8;
  85. }
  86. }
  87.  
  88. function loadXML(loaded)
  89. {
  90. if (loaded)
  91. {
  92. xmlNode = this.firstChild;
  93. a = [];
  94. o = {};
  95. total = xmlNode.childNodes.length;
  96. for (i = 0; i < total; i++)
  97. {
  98. var o = {};
  99. o.image = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
  100. o.description = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
  101. o.poolType = xmlNode.childNodes[i].childNodes[2].firstChild.nodeValue;
  102. a.push(o);
  103. } // end of for
  104. preloadImages(a);
  105. }
  106. else
  107. {
  108. content = "file not loaded!";
  109. } // end else if
  110. } // End of the function
  111. function nextImage()
  112. {
  113. preloader._visible = false;
  114. ++p;
  115. p = p % a.length;
  116. picture.loadMovie(a[p].image, 1);
  117. desc_txt.text = a[p].description;
  118. pool_txt.text = a[p].poolType;
  119. picture_num();
  120. clearInterval(myInterval);
  121. if (playing)
  122. {
  123. slideshow();
  124. } // end if
  125. } // End of the function
  126. function prevImage()
  127. {
  128. clearInterval(myInterval);
  129. if (playing)
  130. {
  131. slideshow();
  132. } // end if
  133. if (p > 0)
  134. {
  135. --p;
  136. }
  137. else
  138. {
  139. p = a.length - 1;
  140. } // end else if
  141. picture.loadMovie(a[p].image);
  142. desc_txt.text = a[p].description;
  143. pool_txt.text = a[p].poolType;
  144. picture_num();
  145. } // End of the function
  146. function firstImage()
  147. {
  148. // if (loaded == filesize)
  149. // {
  150. playing = true;
  151. picture.loadMovie(a[0].image, 1);
  152. desc_txt.text = a[0].description;
  153. pool_txt.text = a[0].poolType;
  154. picture_num();
  155. clearInterval(myInterval);
  156. if (playing)
  157. {
  158. slideshow();
  159. } // end if
  160. // } // end if
  161. } // End of the function
  162. function picture_num()
  163. {
  164. current_pos = p + 1;
  165. pos_txt.text = current_pos + "/" + total;
  166. picture._yscale = 80;
  167. picture._xscale = 94;
  168. } // End of the function
  169. function slideshow()
  170. {
  171. function pause_slideshow()
  172. {
  173. clearInterval(myInterval);
  174. nextImage();
  175. } // End of the function
  176. myInterval = setInterval(pause_slideshow, delay);
  177. } // End of the function
  178. delay = 5000;
  179. xmlData = new XML();
  180. xmlData.ignoreWhite = true;
  181. xmlData.onLoad = loadXML;
  182. //xmlData.load("commercial.xml");
  183. listen = new Object();
  184. listen.onKeyDown = function ()
  185. {
  186. if (Key.getCode() == 37)
  187. {
  188. prevImage();
  189. }
  190. else if (Key.getCode() == 39)
  191. {
  192. nextImage();
  193. } // end else if
  194. };
  195. Key.addListener(listen);
  196. previous_btn.onRelease = function ()
  197. {
  198. prevImage();
  199. };
  200. next_btn.onRelease = function ()
  201. {
  202. nextImage();
  203. };
  204. p = 0;
  205. var myInterval;
  206. playing = true;
  207. play.onPress = function ()
  208. {
  209. playing = true;
  210. desc_txt.text = a[p].description;
  211. pool_txt.text = a[p].poolType;
  212. picture_num();
  213. clearInterval(myInterval);
  214. if (playing)
  215. {
  216. slideshow();
  217. } // end if
  218. };
  219. play.onRelease = play.onReleaseOutside = function ()
  220. {
  221. this.gotoAndStop("_disabled");
  222. };
  223. stop.onPress = function ()
  224. {
  225. playing = false;
  226. clearInterval(myInterval);
  227. };
  228. if (gus.playpause == "pause")
  229. {
  230. playing = false;
  231. clearInterval(myInterval);
  232. } // end if

Report this snippet  

You need to login to post a comment.