Guest User

Untitled

a guest
Jun 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.69 KB | None | 0 0
  1. var thumbArr:Array = new Array();//for thumbs
  2. var mcArr:Array = new Array();//holds all box movieclips
  3.  
  4. var whichCategoryXML:String = "category1.xml";
  5. loadFirstTime(whichCategoryXML);//first time
  6.  
  7. var categoryXML:XML = new XML();
  8. var categoryXMLLoader:URLLoader;//
  9.  
  10. function loadFirstTime(whichCategoryXML:String):void {
  11. categoryXMLLoader = new URLLoader();
  12. categoryXMLLoader.addEventListener(IOErrorEvent.IO_ERROR, ioError_categoryXML, false, 0, true);
  13. categoryXMLLoader.addEventListener(ProgressEvent.PROGRESS, progress_categoryXML, false, 0, true);
  14. categoryXMLLoader.addEventListener(Event.COMPLETE, complete_categoryXML, false, 0, true);
  15. categoryXMLLoader.load(new URLRequest(whichCategoryXML));
  16. }
  17. function ioError_categoryXML(e:IOErrorEvent):void {
  18. trace("ioError_categoryXML: " + e);
  19. }
  20. function progress_categoryXML(e:ProgressEvent):void {
  21. }
  22. function complete_categoryXML(e:Event):void {
  23. categoryXML=XML(e.target.data);
  24. for (var i:int = 0; i < categoryXML.image.length(); i++) {
  25. thumbArr.push(categoryXML.image[i].thumb);
  26. }
  27. categoryXMLLoader.removeEventListener(IOErrorEvent.IO_ERROR, ioError_categoryXML);
  28. categoryXMLLoader.removeEventListener(ProgressEvent.PROGRESS, progress_categoryXML);
  29. categoryXMLLoader.removeEventListener(Event.COMPLETE, complete_categoryXML);
  30. categoryXMLLoader=null;
  31.  
  32. startLoading();
  33. }
  34. function startLoading():void {
  35. addEventListener(Event.ENTER_FRAME, center, false, 0, true);
  36. for (var i = 0; i < categoryXML.image.length(); i++) {
  37. var box:Box = new Box();
  38. mcArr.push(box);
  39.  
  40. box.title_txt.text = categoryXML.image[i].title;
  41. box.topic_txt.text = categoryXML.image[i].topic;
  42.  
  43. box.addEventListener(MouseEvent.CLICK, clickThumb, false, 0, true);
  44. box.addEventListener(MouseEvent.ROLL_OVER, overThumb, false, 0, true);
  45. box.addEventListener(MouseEvent.ROLL_OUT, outThumb, false, 0, true);
  46. box.addEventListener(MouseEvent.MOUSE_DOWN, startDragThumb, false, 0, true);
  47. box.addEventListener(MouseEvent.MOUSE_UP, stopDragThumb, false, 0, true);
  48. box.mouseChildren = false;
  49. thumbSprite.addChild(box);
  50.  
  51. }
  52. //
  53. var row:int = 5;//rows in horizontal by default
  54. var limit:int = categoryXML.image.length();
  55. var col:int = Math.ceil(limit/row);
  56. createGrid(col,row,260,86,5,5, false);//returns point array
  57.  
  58. tweenThumbs();//tweens movieClips to their position on stage
  59. loadImage();
  60. }
  61. function loadImage():void {
  62. thumbLoader = new Loader();
  63. thumbLoader.load(new URLRequest(thumbArr[0]));
  64. thumbLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, thumb_IOError, false, 0, true);
  65. thumbLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, thumb_Progress, false, 0, true);
  66. thumbLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, thumb_Complete, false, 0, true);
  67. thumbArr.splice(0,1);
  68. }
  69. function thumb_IOError(e:IOErrorEvent):void {
  70. trace("thumb_IOError: " + e);
  71. }
  72. function thumb_Progress(e:ProgressEvent):void {
  73.  
  74. }
  75. function thumb_Complete(e:Event):void {
  76. e.target.removeEventListener(IOErrorEvent.IO_ERROR, thumb_IOError);
  77. e.target.removeEventListener(ProgressEvent.PROGRESS, thumb_Progress);
  78. e.target.removeEventListener(Event.COMPLETE, thumb_Complete);
  79.  
  80. mcArr[loadedThumbs].addChild(thumbLoader);
  81. thumbLoader.x = thumbLoader.y = 8;
  82.  
  83. mcArr[loadedThumbs].preloader_mc.stop();//this line works
  84.  
  85. trace(mcArr[loadedThumbs].preloader_mc);//it traces just fine one way or another
  86. for(var i:int = 0;i<mcArr[loadedThumbs].numChildren;i++){
  87. trace(mcArr[loadedThumbs].getChildAt(i).name);
  88. }
  89.  
  90. mcArr[loadedThumbs].removeChild(mcArr[loadedThumbs].getChildByName("preloader_mc"));//this line causes an error
  91. //TypeError: Error #2007: Parameter child must be non-null. at flash.display::DisplayObjectContainer/removeChild() at MethodInfo-108()
  92. mcArr[loadedThumbs].preloader_mc = null;
  93.  
  94. if (thumbArr.length>0) {
  95. loadedThumbs++;
  96. loadImage();
  97. }else {
  98. trace(finished);
  99. }
  100. }
  101. //**********************************************************************************************
  102. function clickCategory(e:MouseEvent):void {
  103.  
  104. for each (var item in mcArr) {
  105. item.removeEventListener(MouseEvent.CLICK, clickThumb);
  106. item.removeEventListener(MouseEvent.ROLL_OVER, overThumb);
  107. item.removeEventListener(MouseEvent.ROLL_OUT, outThumb);
  108. item.removeEventListener(MouseEvent.MOUSE_DOWN, startDragThumb);
  109. item.removeEventListener(MouseEvent.MOUSE_UP, stopDragThumb);
  110. }
  111. for(var i:int = 0;i< mcArr.length;i++){
  112. thumbSprite.removeChild(mcArr[i]);
  113. mcArr[i] = null;
  114. }
  115.  
  116. //reset all
  117. mcArr = [];
  118. imageArr = [];
  119. pointArr = [];
  120. thumbArr = [];
  121. loadedThumbs = 0;
  122.  
  123. var whichCategoryXML:String = "category" + e.target.id + ".xml";
  124. loadFirstTime(whichCategoryXML);
  125. }
Add Comment
Please, Sign In to add comment