0
votes

Normally my preloader is 20 frames and looks like this:

Frame 1 Actionscript:

var amountLoaded:Number = _root.getBytesLoaded()/_root.getBytesTotal();
preloader._width = amountLoaded * 200;
loadText.text = Math.round(amountLoaded * 100) + "%";

if(_root.getBytesLoaded() == _root.getBytesTotal())  {
     gotoAndPlay(21);
}

else {
     gotoAndPlay(1);
}

On Frame 20, we obviously have:

this.gotoAndPlay(1);

This works fine, but it is only the home page I want the intro of my flash to play. Therefore, I use FlashVars on every other page than the home page to tell the animation where it should skip to.

To do this, I have placed this on the first frame after the preloader:

gotoAndPlay(AdFrame);

and in every page except the home page, I have added this Flash Variable:

<param name="FlashVars" value="AdFrame=39" />

My question: How can I skip the preloader entirely if the animation is loaded?

My failed attempt: I have tried moving my preloader to start on frame 2, and on frame one, changed:

var amountLoaded:Number = _root.getBytesLoaded()/_root.getBytesTotal();
preloader._width = amountLoaded * 200;
loadText.text = Math.round(amountLoaded * 100) + "%";

if(_root.getBytesLoaded() == _root.getBytesTotal())  {
     gotoAndPlay(AdFrame);
}

else {
     gotoAndPlay(2);
}

But it still does not bypass the preloader.

Any idea on how I can skip the preloader entirely if the content is loaded?

1
do you have an enterFrame in your scriptmgraph
mgraph: No, I do not. Do you know if that would help?WebMW
@mgraph 1) Try gotoAndStop where? On my failed attempt first IF statement? If so, that doesn't make sense because the condition is going to the "else" on my failed attempt. 2) Add stop(); to the last keyframe of the entire animation or to the last keyframe of the preloader? Neither would make sense.WebMW
The problem is that the code: preloader._width = amountLoaded * 200; loadText.text = Math.round(amountLoaded * 100) + "%"; doesn't correctly constitute loaded (cached) content. I don't know what else I can use, but it would be great to add in a line about "IF CACHED" go HERE! (Ya know?)WebMW
What do you mean by "it doesn't bypass the preloader"? Do you mean it's visible briefly at 100% before the frames progress?net.uk.sweet

1 Answers

0
votes

If I understand this correctly, your condition does not evaluate to true because on the first frame the values returned by the getBytesLoaded and getBytesTotal methods are not the same even when the SWF is loaded from the browser cache.

If this is the case, you could try waiting before checking the load status. Simply moving your code to frame 2 and the start of your preloader animation to frame 3 might be enough. (It's a long time since I've had to work with the timeline but I seem to remember that waiting a frame was often a good rule of thumb).

Alternatively you could pause for a short interval on the first frame before executing your check:

stop();

var interval = setInterval(function() {

    clearInterval(interval);

    var amountLoaded:Number = _root.getBytesLoaded()/_root.getBytesTotal();
    preloader._width = amountLoaded * 200;
    loadText.text = Math.round(amountLoaded * 100) + "%";

    if(_root.getBytesLoaded() == _root.getBytesTotal())  {
         gotoAndStop(3);
    }

    else {
         gotoAndStop(2);
    }
}, 500); 

You can play around with the interval duration (half a second may be excessive). Note that the interval will be executed each time the play-head is returned to the first frame which, depending on the length of your interval, may not be a problem. If it is a problem, you could consider setting a boolean flag the first time the interval is executed so you can avoid executing it again on subsequent loops.