Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    New Coder
    Join Date
    Nov 2007
    Posts
    72
    Thanks
    0
    Thanked 1 Time in 1 Post

    Preloading Question

    This is something that's bugged me for years and I've just never gotten around to addressing it.

    Say I've got a movie with a bitmap (that's has a relatively large filesize) for a background that starts on frame 2 and a preloader (which is entirely vector and therefore not that big of a file) that is on frame 1. Even though the bitmap hasn't loaded yet, the movie still stalls until it has loaded, making the preloader seemingly start at say 60 or 70 percent.

    Can anyone here explain to me what's going on and what I could maybe do to fix it?

  • #2
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    It depends on how your preloader is setup. Does it load by frames or by filesize? Do you have some code to show?

  • #3
    New Coder
    Join Date
    Nov 2007
    Posts
    72
    Thanks
    0
    Thanked 1 Time in 1 Post
    Sure. It's a simple onEnterFrame that cycles and checks the loaded bytes against the total bytes. Here's the code:

    Code:
    this.onEnterFrame = function() {
    if (picture_one_mc._loaded && picture_two_mc._loaded && picture_three_mc._loaded) {
    	delete this.onEnterFrame;
    			
    	var pre_out:Tween = new Tween(preload_mc, '_alpha', Regular.easeOut, 100, 0, 5, false);
    	pre_out.onMotionFinished = function() {
    		_root.play();
    	}
    			
    } else {
    	var bl:Number = (picture_one_mc.picture_mc.getBytesLoaded() + picture_two_mc.picture_mc.getBytesLoaded() + picture_three_mc.picture_mc.getBytesLoaded() + _root.getBytesLoaded());
    	var bt:Number = (picture_one_mc.picture_mc.getBytesTotal() + picture_two_mc.picture_mc.getBytesTotal() + picture_three_mc.picture_mc.getBytesTotal() + _root.getBytesTotal());
    	preload_mc.bar_mc._width = Math.floor((bl / bt) * 305);
    }
    }
    I'd like to point out that the picture_one_mc._loaded stuff is based on individual images being called to load. They're just booleans that help me to know if I should even worry about the preloader at all.
    Last edited by aWishResigned; 04-17-2008 at 11:05 PM.

  • #4
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    I think your math is more complicated than it needs to be.

    Assuming it is on the first frame, root timeline, why not try

    Code:
     else {
    	var bl:Number = Math.round(this.getBytesLoaded());
    	var bt:Number = Math.round(this.getBytesTotal());
    	preload_mc.bar_mc._width = Math.round(bl / bt * 100 * 305);
    }
    This would just get the size of the movie, and not have to pull the individual elements.

  • #5
    New Coder
    Join Date
    Nov 2007
    Posts
    72
    Thanks
    0
    Thanked 1 Time in 1 Post
    You're exactly right and, if it were any other project, I would agree wholeheartedly. This particular project involves cues within a movie which mean that they have to be loaded before the movie even starts.

    This is just a generic code block to illustrate my point better:
    Code:
    stop();
    this.onEnterFrame = function() {
      var bl:Number = _root.getBytesLoaded();
      var bt:Number = _root.getBytesTotal();
      
      if (bl >= bt) {
        delete this.onEnterFrame;
        _root.play();
      } else {
        preload_mc.bar_mc._width = Math.round((bl / bt) * 300);
      }
    };

  • #6
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Ok, cues within the Flash video? The term movie is ambiguous

  • #7
    New Coder
    Join Date
    Nov 2007
    Posts
    72
    Thanks
    0
    Thanked 1 Time in 1 Post
    Yes, cues within a flash video but, what I meant was that the fact that there was a video in the movie is not important. All I'm looking for is to know how flash will load a movie. If, when there is a large filesize in frame 2, why can't I get a preloader to start eariler in frame 1. It will usually just be a white screen and then appear when the preloader is about halfway complete.

  • #8
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    I take it you've tried the simplified version of the code? Is the file in frame 2 being loaded from an external source or as part of the swf?

    Do you have the page url to show? I'm curious to see this, maybe I'll understand better. I'm not sure I can answer this, but I still don't know why you need to add the three movieclip sizes together, and then use the entire filesize. It seems (in my understanding) that you are actually adding up the total twice.

  • #9
    New Coder
    Join Date
    Nov 2007
    Posts
    72
    Thanks
    0
    Thanked 1 Time in 1 Post
    Quote Originally Posted by jeremywilken View Post
    I take it you've tried the simplified version of the code?
    By the simplified version, do you mean the jumping back and forth between two frames as opposed to using an onEnterFrame? If so, then yes, I have and I've moved on to this.

    Quote Originally Posted by jeremywilken View Post
    Do you have the page url to show? I'm curious to see this, maybe I'll understand better. I'm not sure I can answer this, but I still don't know why you need to add the three movieclip sizes together, and then use the entire filesize. It seems (in my understanding) that you are actually adding up the total twice.
    As of right now, no I don't. The fact that I had other images being loaded with the root is not the issue here. Those other images are being loaded based off of an xml file so that the client can change the pictures that will show on top of the *.flv file. (Think of a television news anchor with a picture about the news story to the side of him. The client, who is speaking in the film wants to have pictures that he's uploaded to show as he's talking.) So, in order for the pictures to be guaranteed to show up at the right time and actually be there, I made the preloader check to see if they're all loaded.

    The question I have is that, if you just had a normal flash file with no outside resources being loaded in (the only elements in the *.swf are the ones that were in the library at compile time), why, when you only have a small vector progress bar, will it not display right off and show the progress of the whole movie being loaded? As it stands right now, if I use a bitmap for a background (or have some large file in the next frame), the preloader will only appear once the *.swf file has already loaded about 40-60%.

    What about the procedures that Flash uses to download *.swf files do I need to know or know better to be able to make the preloader show at 1%?

  • #10
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    By simplified I meant the code I posted that reduced the math.

    Can you post the FLA? Just remove the big images and put some kind of placeholder so I can see the structure. It doesn't make sense, which is why I want to see the structure of the file.

  • #11
    New Coder
    Join Date
    Nov 2007
    Posts
    72
    Thanks
    0
    Thanked 1 Time in 1 Post
    Since I'm talking about all *.fla files in general, I made a quick and dirty one for you. Run it, drop the simulation speed down to 56k and simulate the download. The preloader doesn't show until about 25-26%.

    Can't seem to upload it here so the url is: http://www.globalnetdesigns.com/stephen/test.zip

  • #12
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Ok I get your question.

    http://www.senocular.com/flash/tutorials/faq/

    If your file isn't all that large, then the swf might have a larger percentage of the file loaded before getting rendered on the page. So by the time enough of the SWF is loaded to play the first frame, it might have already gotten more than enough loaded to set your bar above 0%.

  • #13
    New Coder
    Join Date
    Nov 2007
    Posts
    72
    Thanks
    0
    Thanked 1 Time in 1 Post
    Thanks. Got what I needed.


  •  

    Posting Permissions

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