dcsimg
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: i need a generic xml load progress component

  1. #1
    Member
    Join Date
    Aug 2004
    Location
    UK
    Posts
    88

    i need a generic xml load progress component

    can anybody point me to an example of a compenent/object that listens for all xml sendandloads. i have a movie that gets its xml content from 3 or 4 php scripts depending on its context and what movieclips are instanciated. I would like a way of running an animation when the movie is loading xml without testing each individual clip for its load progress (i can do it that way but there must be a better more OO way of doing it!?).

    is there a global sendandload listener for the stage?? if not i was thinking of developing a component that the individual clips can register themsleves with when their load is triggered, and then remove themselves from when their onLoad functions are called. this component will cycle an animation rather than indicate actually load progress (a load progress incidator is a bit over kill for 20k - 70ks worth of data - i just want to show that there is some background activity when the user is waiting for the page to render) somebody must have done this already!!??
    http://robotnic.co.uk/
    -----------------------------------------

  2. #2
    Member
    Join Date
    Aug 2004
    Location
    UK
    Posts
    88
    ok ive done it now...
    http://robotnic.co.uk/
    -----------------------------------------

  3. #3
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    out of interest, which way did you go with this one

  4. #4
    Member
    Join Date
    Aug 2004
    Location
    UK
    Posts
    88
    ok - it turned out pretty neat in the end, but i would be interested in your comments - here is the component code:

    Code:
    #initclip
    //-------------------------------------------------------------//
    function fieldClass() {
    
    	// register this clip as _root.ldr
    	_root.ldr = this;
    	
    	this.ldrArr = new Array();
    		
    	// animation stuff
    	this.fieldArr = new Array;
    	for(i=0; i<=15; i++){
    		this.fieldArr.push(eval("this."+i));
    	}	
    	this.q = 15;
    	
    	this.numberOfLoadingMovieClips = 0;
    
    }
    //-------------------------------------------------------------//
    fieldClass.prototype = new MovieClip();
    //-------------------------------------------------------------//
    fieldClass.prototype.removeMe = function(){
    	this.numberOfLoadingMovieClips--;
    }
    
    //-------------------------------------------------------------//
    fieldClass.prototype.addMe = function(inst) {
    	this.ldrArr.push(inst);
    	this.numberOfLoadingMovieClips++;
    }
    
    //-------------------------------------------------------------//
    fieldClass.prototype.onEnterFrame = function () {
    	
    	if(this.numberOfLoadingMovieClips > 0 || !this.atleastonce){
    		
    		// run animation
    		if(this.q>=0){
    			this.done = false;
    			this.atleastonce = false;
    			this.fieldArr[this.q].play();
    			this.q--;			
    		} else {
    			this.atleastonce = true;
    			this.q=15;		
    			this.fieldArr[this.q].play();
    			this.q--;		
    		}
    		
    	} else {
    		if(!this.done){
    			// call back for all movie clips that have registered themselves during this loading process
    			for(j=0; j<this.ldrArr.length; j++){
    				this.ldrArr[j].render();
    			}
    			this.done = true;
    			delete this.ldrArr;
    			this.ldrArr = new Array();
    		}
    	}
    	
    }
    
    Object.registerClass("field", fieldClass);
    
    #endinitclip
    code on clips that need to load xml:

    Code:
    this.loadContent = function(){
          _root.ldr.addMe(this);
         // then some code to load the xml....
    }
    
    this.contentLoaded = function(){
          _root.ldr.removeMe();
    }
    
    this.render = function(){
          //do something when everything has loaded. ie display this clips loaded content
    }
    so how does it work? - first off when the clip to load xml calls its load function it adds its self to an array on the the ldr clip and increments this.numberOfLoadingMovieClips. the ldr clip has an onEnterFrame that is testing for a value of this.numberOfLoadingMovieClips that is more that 0 - once this condition has been met it starts the animation.

    at this point further clips can register/remove themselves in the same way. the animation will then run until this.numberOfLoadingMovieClips == 0 or the animation has run at least once (if the data comes back realy quickly it looks a bit odd as animation only runs for a couple of frames).

    then the _root.ldr clip calls a render function on all the clips that haves registered with it during this global load - this basically tells the invidual clips that all the loading for this view is over and its ok to display its content

    hope this makes sense!? - i have added and example .fla using button actions rather than xml loads to demo.
    Attached Files Attached Files
    Last edited by tiny_legoman; 03-03-2008 at 07:47 AM.
    http://robotnic.co.uk/
    -----------------------------------------

  5. #5
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    thanks for the heads-up

    neat coding

  6. #6
    Member
    Join Date
    Oct 2006
    Location
    UK
    Posts
    43
    Yeah, this does seem basically what I was after, I do seem to be struggling with how it works and implementation though. Could I get an example with an xml file possibly? Or just a little help.

    Sorry to be a hastle. Tim.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center