Groups | Blog | Home
all groups > flash (macromedia) > december 2003 >

flash (macromedia) : onLoad vs. cache


adamr1001
12/6/2003 8:00:00 PM


When I define an 'onLoad' function for an MP3 that is loaded off the server as an event - the function does not get called if the MP3 is already in the user's cache. Is there a way to fix this?

Thanks in advance.

adamr1001
12/6/2003 10:37:34 PM
Thanks for your reply John.

I tried your test method, and the function is not firing once the mp3 is in the user's cache.

I am also getting variable results Flash's perceptions of how much of the mp3 has been loaded.
Sometimes, at seemingly random occasions, Flash thinks that the mp3's bytes loaded is equal to the total when it cannot possibly be. I can usually trigger this strange result by refreshing the page mid-way through the loading process, but sometime i get this results on the first visit to the site, even when the cache has been cleared.

Perhaps I can send you my code?

I really appreciate your help.



Laiverd.COM
12/6/2003 10:46:05 PM
What makes you so sure the function doesn't fire?; what would be more
logical is that the function does fire but as the mp3 is already in cache,
it simply does not have to be downloaded again; which seems an advantage to
the user to me ;-)

You can pretty simply check whether the function fires or not by putting

getURL("javascript:alert('function was fired');");

right after the first line of the function declaration. If the alert fires;
the function is called. It would surprise me if the function would not fire
due to caching.

John

--
----------------------------------------------------------------------------
-----------------------------------------
RESOURCES
http://groups.google.com/advanced_group_search?hl=en&as_ugroup=*flash
----------------------------------------------------------------------------
-----------------------------------------
TUTORIALS
Flash & PHP Emailform:
http://home.hccnet.nl/john.mulder/flash/tutorials/flash_php_mailform.zip
----------------------------------------------------------------------------
-----------------------------------------

Laiverd.COM
12/7/2003 12:15:54 AM
Post the code here then, as this can hardly be a cache issue. Something
weird going on here ;-) O: maybe elaborate also on why it creates a problem.

John

--
----------------------------------------------------------------------------
-----------------------------------------
RESOURCES
http://groups.google.com/advanced_group_search?hl=en&as_ugroup=*flash
----------------------------------------------------------------------------
-----------------------------------------
TUTORIALS
Flash & PHP Emailform:
http://home.hccnet.nl/john.mulder/flash/tutorials/flash_php_mailform.zip
----------------------------------------------------------------------------
-----------------------------------------

adamr1001
12/7/2003 3:02:33 AM
Thanks again for your reply John.

This creates a problem because users will be visiting a webpage, and the mp3 must load correctly.
The successful loading of the mp3 is crucial to the success of the website.

I am not using the onLoad function - but unstead I am testing the bytes loaded.
This solves the caching issue.

Here is the new problem (incredibly strange):
Sometimes, not all the time but only sometimes when I load the page (with my cache cleared) Flash thinks that the bytes loaded is equal to the total bytes.

Try it out - if it says "Playing" and if the time is "0:00 | 0:00" then the file isnt really loaded. But you'll see that the KB loaded displays as being equal to the total. its so weird. you can trigger this strange result by click refresh a bunch of times while the file is loading.

The consequence is that the 'play' function fires, which means that is won't fire when the file actually loads. Another consequence is that the user has no idea that the file is loading, because flash thinks its done.

See it at www.amrstudios.com/temp/mp3player


I did not post all my code - just what is relevant.





this.onEnterFrame = function() {
if (!_global.isLoaded) {
disableButtons();
loaded1 = myMusic.getBytesLoaded()/1024;
total1 = myMusic.getBytesTotal()/1024;
if (loaded1 != undefined) {
perc = int((loaded1*100)/total1);
progressBar.bufferPosition._xscale = perc;
status.text = "Loading: ";
status.text += perc;
status.text += "%";
if ((loaded1>4) && (total1>4) && (loaded1 == total1) && (!_global.isStarted)) {
enableButtons();
playSound();
ppbutton.gotoAndStop("play");
_global.isLoaded = true;
}
} else {
myMusic.loadSound(_global.sourceFile, false);
}
} else {
_global.dur = myMusic.duration;
_global.pos = myMusic.position;
this.totalTime = _global.dur/1000;
this.elapsedTime = _global.pos/1000;
}
showTime(this.totalTime, this.elapsedTime);
};

Laiverd.COM
12/7/2003 1:30:19 PM
Sorry, it's sunday morning here and maybe I'm not awake, but I don't see any
problem in that code at first sight. I'd start debugging by tracing of every
variable and hope that gives you some more insights.

For now I wish you luck.

John

--
----------------------------------------------------------------------------
-----------------------------------------
RESOURCES
http://groups.google.com/advanced_group_search?hl=en&as_ugroup=*flash
----------------------------------------------------------------------------
-----------------------------------------
TUTORIALS
Flash & PHP Emailform:
http://home.hccnet.nl/john.mulder/flash/tutorials/flash_php_mailform.zip
----------------------------------------------------------------------------
-----------------------------------------

One Louder
12/7/2003 9:20:44 PM
When you're comparing getBytesLoaded() to getByteTotal(), you should also make sure they're rational as well as equal.

There's a period between the issuing of your request and the response from the server where getBytesTotal() returns a small number, sometimes zero, but I've seen 18 occasionally. This is because is has to get a response before it knows the size of the file - if you ask prematurely, it returns *something* for both values, and they may indeed be equal (and wrong).

So your logic should go something like this:

var gbt = myClip.getBytesTotal();
var gbl = myClip.getBytesLoaded();
if (gbt>100 && gbl==gbt) {
// file is loaded
} else {
// file still loading
}


The '100' is just some number greater than anything getBytesTotal() will return before the server response, and smallar than any rational size of an external movie. You can mess with it to find a better number.





adamr1001
12/10/2003 6:31:04 AM
Thanks for your response.

I have already accounting for that by using the following line:

if ((loaded1>4 ) && ( total1>4 ) && (loaded1 == total1) && (!_global.isStarted)) { ...


My problem is that loaded1 is sometimes returning as the total.
It's very strange.

I have never had a problem with Flash regarding using variables on the fly.

Perhaps it's being picky all of the sudden... but that can't make sense...

I dunno.

I'm clueless.

I have a way to work around my problem - but fixing this inconsistency wold make the app. sigifcantly smoother and will dramatically improve its reliability in the eyes of the user.

Thanks,

Adam


KevPartner
6/8/2004 8:50:00 PM
i have exactly the same problem. It occurs if you create a sound object then
use loadsound to load the MP3 into it. It never seems to happen on the first
sound object but sometimes, when a new MP3 is loaded, the getBytesLoaded and
getBytesTotal are instantly the same value. So, if you have a Start command
that is based on getBytesLoaded/getBytesTotal, then it will attempt to start a
sound even though nothing has been loaded. I have spent DAYS monkeying around
with this. The only answer appears to load the sound using the streaming
option, but this causes other problems if you want something to synchronise
with the sound.
Kev
AddThis Social Bookmark Button