dcsimg
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: loading swf with preloader into my main movie

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

    loading swf with preloader into my main movie

    hi

    i am loading a swf into a placeholder mc (movieloadmc) but cannot get the preloader inside the swf to work. this is the code on a 2 frame loop inside the swf:

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

    loadBarFill._xscale = ((this.getBytesLoaded() / this.getBytesTotal()) * 100); // graphic readout

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

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

    the next frame loops back to the above code until the movie is loaded.

    i thought the above would work but it doesn't. i've tried out a number of targetting variants:

    this.getBytesLoaded()..
    getBytesLoaded()..
    _root.movieloadmc.getBytesLoaded()..
    _level0.movieloadmc.getBytesLoaded()..

    even

    _parent.getBytesLoaded()..

    and none of them work!

    the swf preloader works fine in test mode on its own but not when the swf is actually loaded into the main movie (into the movieloadmc clip). instead the swf remains blank until it has fully loaded and then just fades in, without the preloader bar or dynamic textfield working.

    would i be better off placing an onClipEvent(enterFrame) script on the movieloadmc clip (as i've seen elsewhere)? why should this be any better though?

    and if so, i guess i would then need to target a textfield readout / loader bar graphic in the main movie rather than the incoming swf..

    any help much appreciated, thanks!

  2. #2
    Maya * ActionScript Addict DangerAhead's Avatar
    Join Date
    Jun 2000
    Location
    San Francisco
    Posts
    299
    Because when your code is ON a movieclip, you have to put your code in some event handler like onData or onEnterFrame, etc.

    for external SWF loading, I like onData because it fires for every frame it loads instead of onEnterFrame which keeps firing even if you're not doing anything.

    I would use onData if I were loading a swf into an MC.


    Code:
    this.onData = function (){
    
         loadPercent = (Math.floor (this.getBytesLoaded() / this.getBytesTotal() * 100) + "%"); 
    
         loadBarFill._xscale = ((this.getBytesLoaded() / this.getBytesTotal()) * 100); // graphic readout
    
         if ((this.getBytesLoaded() == this.getBytesTotal()) && (this.getBytesTotal()) > 20)){ 
    
               loadPercent = "100%";
               this.gotoAndPlay("startintro"); //Where to go once the movie is loaded
    
       }
    }
    Geordie Martinez
    www.citizenparanoid.com | email

  3. #3
    Senior Member
    Join Date
    Sep 2000
    Posts
    133
    thanks for the reply.

    firstly, my code isn't ON a movieclip, it's in a frame (2 frame loop).

    do you advise putting the code ON an mc or is there a way of changing it so i can keep the 2 frameloop set up i currently have?

    also, if you include..

    && (this.getBytesTotal()) > 20)

    does this mean that my graphic readout (loadBarFill) won't actually do anything until 20% of the incoming swf has actually loaded??

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

    another question..

    in your code..

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

    loadBarFill._xscale = ((this.getBytesLoaded() / this.getBytesTotal()) * 100);


    where is the loadPercent text box and the loadBarFill graphic mc actually situated? should they be in the loaded swf or in the main movie?

  5. #5
    Senior Kid
    Join Date
    Jan 2002
    Location
    I am right behind ya
    Posts
    274
    you need to indicate the loading swf's byteTotal and byteloaded... use that SWF's instance, whatever you set earlier. so your reloading script should be somewhat like this:

    var bytesLoaded = whateverInstanceYouAssignedToTheLoadingSWF.getByte sLoaded();

    var bytesTotal = whateverInstanceYouAssignedToTheLoadingSWF.getByte sTotal();

    loadBarFill._xscale = bytesLoaded / bytesTotal * 100;

    i am actually pretty confused with your movie structure, maybe you should post your loadmovie part of the code
    Last edited by dancinkid6; 09-19-2005 at 04:55 PM.
    -The Dancin kidd

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

    the movie structure is pretty straightforward..

    ..click a button to load a swf into an mc holder clip (movieloadmc). what i can't seem to get working is a preloader for the incoming swf..

    i've tried having the preloader code (frame loop) in the incoming swf, as well as ON the mc holder clip, but neither approach is working.

    the important thing with the preloader script is that it controls both text and graphic readouts (loadPercent & loadBarFill) so that the user can see what's happening.

    my deadline is looming (tomorrow) and i'm no nearer a solution!

    PLEASE HELP if you can.. thanks..

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