Using KennyB's attachSound preloader without a button

Hellow fellow Flashers,

I’ve spent my entire weekend trying to get this working properly, and have combed through as many message boards and sites as possible. I could really use a hand…

I have followed the Kenny Bellew tutorial for preloading when using attachSound. It works pefectly when I use a button to initiate the loading, but acts wonky when I try to do it automatically. Anyone ever encounter this before?

[URL=“http://www.pixelsandpitches.com/preloadthat.html”]http://www.pixelsandpitches.com/preloadthat.html

Here is one test version I have been playing with. The part that is REALLY confusing me is that if I keep refreshing my page, sometimes the preloader will start as it should. Most times it just jumps ahead. (I have also tried it with clearing my cache each time…)

this is my code on my actionscript movie clip as demonstrated in the tutorial:

onClipEvent (load) {
    _root.loadSound = 1;
    _root.soundHolder.loadMovie("externalSoundObjects.swf");
    _root.loadBar._xscale = 0;
}
// 
onClipEvent (enterFrame) {
    if (_root.loadSound == 1) {
        soundsBytesTotal = _root.soundHolder.getBytesTotal();
        soundsBytesLoaded = _root.soundHolder.getBytesLoaded();
trace (soundsBytesTotal)
trace (soundsBytesLoaded)
        percentLoaded = Math.round((soundsBytesLoaded/soundsBytesTotal)*100);
        if (percentLoaded>0) {
            _root.percentLoadedText = percentLoaded+"%";
            // Updates text box with the percent loaded.
            _root.loadBar._xscale = percentLoaded;
            // Causes movie clip "loadBar" to scale horizontally equal to the percentLoaded.
        }
        if (percentLoaded>99 && doOnce != 1) {
            doOnce = 1;
            _root.gotoAndStop("start");
        }
    }
}

Note that I put a trace in for **soundsBytesTotal and soundsBytesLoaded **because for some reason these both come up as “4” first time around - I think this must have something to do with it.

thanks muchly for any pointers!
mrfritter

…excuse me talking to myself here… I’m still puzzled by this & I have been constantly trouble-shooting.

I realize what is happening - but I’m not sure why. Maybe I can clarify.

Since soundsBytesTotal and soundsBytesLoaded come through as “4” each on the first pass, percentLoaded = 100% … therefore the script thinks everything is loaded and goes to frame “x”.

Does anybody know of a reason why the value of “4” comes up on the first pass? I’m testing with a file that’s about 1.6MB, and the first loaded number after 4 is 6226 on a T1 simulated download.

I hope someone has had a similar problem before, I’ve put so much time into this and I’m sure there’s a really simple solution!

cheers,
mrfritter

:smiley: solved my problem… sometimes talking to yourself on a message board helps.

sorry.

(for anyone curious - i altered the if statement that sends you to the next frame as such:)

if (soundsBytesLoaded>4 && soundsBytesLoaded>=soundsBytesTotal)

I still don’t know why it assumes the external swf clip is only 4 bytes upon first enterFrame pass through … but this is a workaround for it.

cheers,
mrfritter.