Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var thumbArr:Array = new Array();//for thumbs
- var mcArr:Array = new Array();//holds all box movieclips
- var whichCategoryXML:String = "category1.xml";
- loadFirstTime(whichCategoryXML);//first time
- var categoryXML:XML = new XML();
- var categoryXMLLoader:URLLoader;//
- function loadFirstTime(whichCategoryXML:String):void {
- categoryXMLLoader = new URLLoader();
- categoryXMLLoader.addEventListener(IOErrorEvent.IO_ERROR, ioError_categoryXML, false, 0, true);
- categoryXMLLoader.addEventListener(ProgressEvent.PROGRESS, progress_categoryXML, false, 0, true);
- categoryXMLLoader.addEventListener(Event.COMPLETE, complete_categoryXML, false, 0, true);
- categoryXMLLoader.load(new URLRequest(whichCategoryXML));
- }
- function ioError_categoryXML(e:IOErrorEvent):void {
- trace("ioError_categoryXML: " + e);
- }
- function progress_categoryXML(e:ProgressEvent):void {
- }
- function complete_categoryXML(e:Event):void {
- categoryXML=XML(e.target.data);
- for (var i:int = 0; i < categoryXML.image.length(); i++) {
- thumbArr.push(categoryXML.image[i].thumb);
- }
- categoryXMLLoader.removeEventListener(IOErrorEvent.IO_ERROR, ioError_categoryXML);
- categoryXMLLoader.removeEventListener(ProgressEvent.PROGRESS, progress_categoryXML);
- categoryXMLLoader.removeEventListener(Event.COMPLETE, complete_categoryXML);
- categoryXMLLoader=null;
- startLoading();
- }
- function startLoading():void {
- addEventListener(Event.ENTER_FRAME, center, false, 0, true);
- for (var i = 0; i < categoryXML.image.length(); i++) {
- var box:Box = new Box();
- mcArr.push(box);
- box.title_txt.text = categoryXML.image[i].title;
- box.topic_txt.text = categoryXML.image[i].topic;
- box.addEventListener(MouseEvent.CLICK, clickThumb, false, 0, true);
- box.addEventListener(MouseEvent.ROLL_OVER, overThumb, false, 0, true);
- box.addEventListener(MouseEvent.ROLL_OUT, outThumb, false, 0, true);
- box.addEventListener(MouseEvent.MOUSE_DOWN, startDragThumb, false, 0, true);
- box.addEventListener(MouseEvent.MOUSE_UP, stopDragThumb, false, 0, true);
- box.mouseChildren = false;
- thumbSprite.addChild(box);
- }
- //
- var row:int = 5;//rows in horizontal by default
- var limit:int = categoryXML.image.length();
- var col:int = Math.ceil(limit/row);
- createGrid(col,row,260,86,5,5, false);//returns point array
- tweenThumbs();//tweens movieClips to their position on stage
- loadImage();
- }
- function loadImage():void {
- thumbLoader = new Loader();
- thumbLoader.load(new URLRequest(thumbArr[0]));
- thumbLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, thumb_IOError, false, 0, true);
- thumbLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, thumb_Progress, false, 0, true);
- thumbLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, thumb_Complete, false, 0, true);
- thumbArr.splice(0,1);
- }
- function thumb_IOError(e:IOErrorEvent):void {
- trace("thumb_IOError: " + e);
- }
- function thumb_Progress(e:ProgressEvent):void {
- }
- function thumb_Complete(e:Event):void {
- e.target.removeEventListener(IOErrorEvent.IO_ERROR, thumb_IOError);
- e.target.removeEventListener(ProgressEvent.PROGRESS, thumb_Progress);
- e.target.removeEventListener(Event.COMPLETE, thumb_Complete);
- mcArr[loadedThumbs].addChild(thumbLoader);
- thumbLoader.x = thumbLoader.y = 8;
- mcArr[loadedThumbs].preloader_mc.stop();//this line works
- trace(mcArr[loadedThumbs].preloader_mc);//it traces just fine one way or another
- for(var i:int = 0;i<mcArr[loadedThumbs].numChildren;i++){
- trace(mcArr[loadedThumbs].getChildAt(i).name);
- }
- mcArr[loadedThumbs].removeChild(mcArr[loadedThumbs].getChildByName("preloader_mc"));//this line causes an error
- //TypeError: Error #2007: Parameter child must be non-null. at flash.display::DisplayObjectContainer/removeChild() at MethodInfo-108()
- mcArr[loadedThumbs].preloader_mc = null;
- if (thumbArr.length>0) {
- loadedThumbs++;
- loadImage();
- }else {
- trace(finished);
- }
- }
- //**********************************************************************************************
- function clickCategory(e:MouseEvent):void {
- for each (var item in mcArr) {
- item.removeEventListener(MouseEvent.CLICK, clickThumb);
- item.removeEventListener(MouseEvent.ROLL_OVER, overThumb);
- item.removeEventListener(MouseEvent.ROLL_OUT, outThumb);
- item.removeEventListener(MouseEvent.MOUSE_DOWN, startDragThumb);
- item.removeEventListener(MouseEvent.MOUSE_UP, stopDragThumb);
- }
- for(var i:int = 0;i< mcArr.length;i++){
- thumbSprite.removeChild(mcArr[i]);
- mcArr[i] = null;
- }
- //reset all
- mcArr = [];
- imageArr = [];
- pointArr = [];
- thumbArr = [];
- loadedThumbs = 0;
- var whichCategoryXML:String = "category" + e.target.id + ".xml";
- loadFirstTime(whichCategoryXML);
- }
Add Comment
Please, Sign In to add comment