views:

80

answers:

2

Hi guys.

I've got a SWF to which I added a Preloader scene. The preloader works fine when I hit Ctrl+Enter in Flash CS4, and select View > Simulate Download.

The preloader displays, and when full, the movie continues as expected.

However, the moment I embed the SWF into some HTML, and load from localhost in any browser, the movie doesn't continue until I right click and select Play.

When I use the Charles Web Debugging Proxy tool and throttle the connection, then again preloading works fine, and the movie proceeds when done?

Any idea what might be going wrong? Here's the source for the preloader:

import flash.events.ProgressEvent;

loaderInfo.addEventListener(ProgressEvent.PROGRESS, update);

function update(e:ProgressEvent):void
{
    var percent:Number = Math.floor((e.bytesLoaded * 100) / e.bytesTotal);

    if(preloaderClip is MovieClip)
    {
        preloaderClip.gotoAndStop(percent);
    }

    if(percent == 100)
    {
        play();
    }
}

// Extra test for IE
var percent:Number = 
    Math.floor((this.loaderInfo.bytesLoaded * 100) / this.loaderInfo.bytesTotal);

if(percent == 100)
{
    nextFrame();
}
stop();
+1  A: 

You likely have some sort of race condition in your code, so that when the loading is near instantaneous it fails to catch the COMPLETE event or something along those lines.

It's very hard to be more specific than that without any code to look at.

grapefrukt
Kewl, I added the source for the preloader, thanks for the prompt reply!
Joe Zephyr
A: 

Yay! Fixed it! I simply added an ADDED_TO_STAGE event listener with the following code:

private function onAddedToStage(event:Event):void
{
    var percent:Number = 
        Math.floor((this.loaderInfo.bytesLoaded * 100) / this.loaderInfo.bytesTotal);

    MonsterDebugger.trace(this, "ADDED_TO_STAGE " + percent + " loaded...");

    if(percent == 100)
    {
        gotoAndPlay("in", "Main");
    }
}
Joe Zephyr