dcsimg
A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: preloader: can i use "this" instead of "_root"?

  1. #1
    Senior Member
    Join Date
    Sep 2000
    Posts
    133

    preloader: can i use "this" instead of "_root"?

    hi

    i need to load some swfs into my main movie.. so i want to reuse the preloader code i already have in that. can i simply replace "this" for "_root" as in the example below?

    loadPercent = (Math.floor (this.getBytesLoaded() / this.getBytesTotal() * 100) + "%");

    if (this.getBytesLoaded() == this.getBytesTotal()){
    loadPercent = "100%";
    gotoAndPlay("startintro");
    }

  2. #2
    Can't Re-Member madzigian's Avatar
    Join Date
    Apr 2004
    Location
    Boston MA
    Posts
    2,662
    yes..... but you have to target the clip you movie is loading into. you can use on onClipEvent (enterFrame) and place that code ON your container clip as well.. but the answer is YES... you can use THIS to load in external swf files..

  3. #3
    Senior Member Dricciotti's Avatar
    Join Date
    Aug 2002
    Posts
    2,988
    Yes. that should work. I usually just use the getBytesLoade() funtion in my maintimeline without _root anyways and it works fine.

  4. #4
    Senior Member
    Join Date
    Sep 2000
    Posts
    133
    using getBytesLoaded() or this.getBytesLoaded() etc on a frame within the incoming swf does NOT work. i've also tried putting the code ON the holder mc but couldn't get this working either..

    maybe i'm doing something else wrong?

    here's my code that's inside the incoming swf:

    loadPercent = (Math.floor (this.getBytesLoaded() / this.getBytesTotal() * 100) + "%"); // dynamic text readout
    loadBarFill._xscale = ((this.getBytesLoaded() / this.getBytesTotal()) * 100); // graphic loader bar readout

    if (this.getBytesLoaded() == this.getBytesTotal()){ //Check for finished loading
    //If loaded, final update to fields
    loadPercent = "100%";

    gotoAndPlay("startintro"); //Where to go once your movie is loaded
    }

    any ideas please???

  5. #5
    Can't Re-Member madzigian's Avatar
    Join Date
    Apr 2004
    Location
    Boston MA
    Posts
    2,662
    try this.....

    Code:
    this.onEnterFrame=function(){
          percent=(this.getBytesLoaded()/this.getBytesTotal())*100;
    	if(!isNan(percent)){
    	// The following only concern the preloader's displays...
    		if (percent == 0) {
    			loadPercent = ""; //this is your dynamic text field
    		} else {
    			loadPercent = "loading...  " + Math.ceil(percent) + "%";
    // this is what is displayed in your dynamic textfield... 
    // it will read "loading... XXX%" (where XXX are the updateing numbers)
    		}
    		this.loadBarFill._visible = true;
    		this.loadBarFill._xscale = percent;
    		if (percent > 1) {
    		}
    	// End of preloader's displays...
    		this.stop();
    	}
        if(percent == 100){
    		trace("LOADED!")
    		// this sends the playhead to the frame label "startintro"
    		// which is placed on the 2nd frame of your movie
    		this.gotoAndPlay("startintro");
    		// this deletes this onEnterFrame event...
    		// so that the movie clip stops looping...
    		delete this.onEnterFrame;
    		// preloader's displays handling..
    		loadPercent = "";
    		this.loadBarFill._visible = false;
    		// end of preloader's displays handling...
    		}
    }
    stop();
    try that... and see if it helps you... that's an altered version of what i use myself... i just changed instance and variable names to match yours...

  6. #6
    Senior Member
    Join Date
    Sep 2000
    Posts
    133

    thanks...

    thanks very much for the code, i'll try it out.

    can you please confirm where i place this code: in the incoming swf frames or on the mc holder clip? i'm getting confused ; )

    thanks again.

  7. #7
    Can't Re-Member madzigian's Avatar
    Join Date
    Apr 2004
    Location
    Boston MA
    Posts
    2,662
    place that code on the first frame of your external swf along with your loadBarFill mc and your loadText dynamic text field. then place the frame label "startintro" on your second frame. should work like a charm...

  8. #8
    Senior Member
    Join Date
    Sep 2000
    Posts
    133

    believe it or not..

    hi

    unfortunately, despite following your instructions precisely, the preloader still isn't working. looking through your nicely commented script, it all makes sense, but it's not actually working!

    basically, because the preloader bar / text readout isn't working, there is no indication that something is actually loading.

    the loaded swf eventually appears some seconds later, so it is being loaded ok.

    if i test the preloader bar / text readout of the swf by using show streaming then it works fine.

    any ideas what might be wrong???

  9. #9
    Can't Re-Member madzigian's Avatar
    Join Date
    Apr 2004
    Location
    Boston MA
    Posts
    2,662
    are you just testing this locally?.. or have you uploaded it to your server to test it?... if you are just testing locally.... you will almost NEVER see a preloader. if you upload it to your server and check it... it should work. if it doesn't.. i'll send you fully functional example.

  10. #10
    Senior Member
    Join Date
    Sep 2000
    Posts
    133
    hi

    yes, i'm testing online, using a 56k modem connection, and the preloader bar and text don't work.

    if i test the swf independently and locally (using show streaming at 56k) then the bar / text readouts do work.

    the website functions fine when using a broadband connection (without preloaders), but at 56k preloaders are necessary.

    i still don't understand why it's not working now at 56k, but if you can send me a fully functioning example that will resolve the problem then that would be very helpful, thanks.

    my email address (if you need it) is:

    darren (at) 3phase (dot) info

  11. #11
    Can't Re-Member madzigian's Avatar
    Join Date
    Apr 2004
    Location
    Boston MA
    Posts
    2,662
    ok.. i'll post a working example here when i have a minute.

  12. #12
    Senior Member
    Join Date
    Sep 2000
    Posts
    133

    thanks

    thanks, i could really do with a working version!

  13. #13
    Can't Re-Member madzigian's Avatar
    Join Date
    Apr 2004
    Location
    Boston MA
    Posts
    2,662
    ok... here you go... to see it in action and working properly.... you can check out THIS LINK

    For the example i made you, i used a preloader in the main movie...(the example files are attached).

    but it would work just as easily if you put the preloader in the external swf files. if you look at the site i'm working on for myself here... i used preloaders in my external movies because of the script i used to control the intro and outtro animations.

    HOPE THAT HELPS... let me know if you have any other questions

    good luck.

  14. #14
    Senior Member
    Join Date
    Sep 2000
    Posts
    133
    thanks very much, i'll take a look at it and report back later.

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