dcsimg
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Yet another preloader issue

  1. #1
    Member
    Join Date
    Jul 2005
    Posts
    81

    Yet another preloader issue

    My preloader script is supposed to trace the loaded bytes and the total bytes, but it isn't doing it.
    What's up? Is it because I am using setInterval?


    code:


    var loaded:Number = 0;
    var getLoaded:Number = 0;
    var delay:Number = 0;

    this.onLoad = function () {
    this.createEmptyMovieClip("holder", 100);
    holder._x = 0;
    holder._y = 0;
    holder._alpha = 0;
    delay = setInterval(preload, 10, this.holder);
    }

    preload = function(mc) {
    mc.loadMovie("main_stage.swf");
    total = Math.round(mc.getBytesTotal());
    getLoaded = Math.round(mc.getBytesLoaded());
    trace("total = "+getLoaded);
    mc._alpha = 0

    if(total< getLoaded) {
    trace("loaded = "+ getLoaded);
    }else{
    trace("total = "+getLoaded);
    trace(mc + " loaded!");
    mc._alpha = 100;
    clearInterval(delay);
    }


    }



  2. #2
    Senior Member Dricciotti's Avatar
    Join Date
    Aug 2002
    Posts
    2,988
    What exactly are you trying to do? Your code is loading the same movie every 10 ms over and over again. If you are trying to make a preloader, put the loadMovie() code outside the preload function and only use setInterval() to check whether or not the movie has been loaded.

  3. #3
    Member
    Join Date
    Jul 2005
    Posts
    81

    Re:

    Okay,
    I just want to be able to recycle the preloader so that it can load different .swf's on the fly, that's why I put the loadMovie function in the code
    Can you give an example of what to do please?

  4. #4
    Senior Member Dricciotti's Avatar
    Join Date
    Aug 2002
    Posts
    2,988
    You only want to load a movie once right? So put that code outside of the loop. Something like this:
    code:
    var loaded:Number = 0;
    var getLoaded:Number = 0;
    var delay:Number = 0;
    this.onLoad = function () {
    this.createEmptyMovieClip("holder", 100);
    holder._x = 0;
    holder._y = 0;
    holder._alpha = 0;
    holder.loadMovie("main_stage.swf");
    delay = setInterval(preload, 10, this.holder);
    }

    preload = function(mc) {

    total = Math.round(mc.getBytesTotal());
    getLoaded = Math.round(mc.getBytesLoaded());
    trace("total = "+getLoaded);
    mc._alpha = 0
    if(total< getLoaded) {
    trace("loaded = "+ getLoaded);
    }else{
    trace("total = "+getLoaded);
    trace(mc + " loaded!");
    mc._alpha = 100;
    clearInterval(delay);
    }
    }


  5. #5
    Member
    Join Date
    Jul 2005
    Posts
    81

    Re:

    Thanks, for that.
    My problem though is that I can't get the code to trace the bytes loaded when I simulate a download. Ultimately, I want this to be used in a percentage bar.

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