We Recommend

Learning Python Learning Python
The authors of Learning Python show you enough essentials of the Python scripting language to enable you to begin solving problems right away, then reveal more powerful aspects of the language one at a time. This approach is sure to appeal to programmers and system administrators who have urgent problems and a preference for learning by semi-guided experimentation.


Posted By

sk8rjess on 03/24/08


Tagged


Versions (?)


BLAH!


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.  
  80. function myFrameEnter(){
  81. picture._width = 200;
  82. }
  83.  
  84. function loadXML(loaded)
  85. {
  86. if (loaded)
  87. {
  88. xmlNode = this.firstChild;
  89. a = [];
  90. o = {};
  91. total = xmlNode.childNodes.length;
  92. for (i = 0; i < total; i++)
  93. {
  94. var o = {};
  95. o.image = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
  96. o.description = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
  97. o.poolType = xmlNode.childNodes[i].childNodes[2].firstChild.nodeValue;
  98. a.push(o);
  99. } // end of for
  100. preloadImages(a);
  101. }
  102. else
  103. {
  104. content = "file not loaded!";
  105. } // end else if
  106. } // End of the function
  107. function nextImage()
  108. {
  109. preloader._visible = false;
  110. ++p;
  111. p = p % a.length;
  112. picture.loadMovie(a[p].image, 1);
  113. desc_txt.text = a[p].description;
  114. pool_txt.text = a[p].poolType;
  115. picture_num();
  116. clearInterval(myInterval);
  117. if (playing)
  118. {
  119. slideshow();
  120. } // end if
  121. } // End of the function
  122. function prevImage()
  123. {
  124. clearInterval(myInterval);
  125. if (playing)
  126. {
  127. slideshow();
  128. } // end if
  129. if (p > 0)
  130. {
  131. --p;
  132. }
  133. else
  134. {
  135. p = a.length - 1;
  136. } // end else if
  137. picture.loadMovie(a[p].image);
  138. desc_txt.text = a[p].description;
  139. pool_txt.text = a[p].poolType;
  140. picture_num();
  141. } // End of the function
  142. function firstImage()
  143. {
  144.  
  145. // if (loaded == filesize)
  146. // {
  147. playing = true;
  148. picture.loadMovie(a[0].image, 1);
  149. desc_txt.text = a[0].description;
  150. pool_txt.text = a[0].poolType;
  151. picture_num();
  152. clearInterval(myInterval);
  153. if (playing)
  154. {
  155. slideshow();
  156. } // end if
  157. // } // end if
  158. } // End of the function
  159. function picture_num()
  160. {
  161. current_pos = p + 1;
  162. pos_txt.text = current_pos + "/" + total;
  163.  
  164.  
  165. } // End of the function
  166. function slideshow()
  167. {
  168. function pause_slideshow()
  169. {
  170. clearInterval(myInterval);
  171. nextImage();
  172. } // End of the function
  173. myInterval = setInterval(pause_slideshow, delay);
  174. } // End of the function
  175. delay = 5000;
  176. xmlData = new XML();
  177. xmlData.ignoreWhite = true;
  178. xmlData.onLoad = loadXML;
  179. xmlData.load("lagoon.xml");
  180. listen = new Object();
  181. listen.onKeyDown = function ()
  182. {
  183. if (Key.getCode() == 37)
  184. {
  185. prevImage();
  186. }
  187. else if (Key.getCode() == 39)
  188. {
  189. nextImage();
  190. } // end else if
  191. };
  192. Key.addListener(listen);
  193. previous_btn.onRelease = function ()
  194. {
  195. prevImage();
  196. };
  197. next_btn.onRelease = function ()
  198. {
  199. nextImage();
  200. };
  201. p = 0;
  202. var myInterval;
  203. playing = true;
  204. play.onPress = function ()
  205. {
  206. playing = true;
  207. desc_txt.text = a[p].description;
  208. pool_txt.text = a[p].poolType;
  209. picture_num();
  210. clearInterval(myInterval);
  211. if (playing)
  212. {
  213. slideshow();
  214. } // end if
  215. };
  216. play.onRelease = play.onReleaseOutside = function ()
  217. {
  218. this.gotoAndStop("_disabled");
  219. };
  220. stop.onPress = function ()
  221. {
  222. playing = false;
  223. clearInterval(myInterval);
  224. };
  225. if (gus.playpause == "pause")
  226. {
  227. playing = false;
  228. clearInterval(myInterval);
  229. } // end if

Report this snippet 

You need to login to post a comment.