all groups > flash actionscript > may 2005 >
You're in the

flash actionscript

group:

onLoad and getBytesLoaded() wierd in IE


onLoad and getBytesLoaded() wierd in IE spreenchy
5/1/2005 12:00:00 AM
flash actionscript:
I'm trying to make an mp3 player that takes a command-line argument from a web
page specifying the filename of the mp3 to load. (I'm using Flash MX, 2002)
It's working, but I'm having trouble adding code to test whether the mp3 has
loaded (to hide the "play" button until then). My movie works with Firefox but
not with Internet Explorer.

This code:
mySample.onLoad = function () {gotoAndPlay("stopped");};
fires appropriately in firefox, but immediately (i.e. before the file has
loaded) in IE.

Further, this code:
Math.floor(((mySample.getBytesLoaded() / mySample.getBytesTotal())*100))
works well to show the percentage loaded in firefox, but always yields 100% in
IE.

HELP!!!!!


Re: onLoad and getBytesLoaded() wierd in IE Blade al'Slayer
5/4/2005 12:00:00 AM
[quoted text, click to view]
Hi, make sure that you place the onLoad statement BEFORE calling
Re: onLoad and getBytesLoaded() wierd in IE spreenchy
5/4/2005 12:00:00 AM
First, thanks so much for replying... I was starting to feel kind of lost in
the wilderness...

Yes I made the mistake of putting the load command before the onLoad()
handler. So, I took your advice and reversed the order of the statements, but
Houston we still have a problem.

This is how I had things ordered before your reply:

mySample = new Sound();
mySample.setVolume(75);
mySample.loadSound("media/" + sample, false);
mySample.onLoad = function () {gotoAndPlay("stopped");};

This is how they look now:

mySample = new Sound();
mySample.setVolume(75);
mySample.onLoad = function () {gotoAndPlay("stopped");};
mySample.loadSound("media/" + sample, false);

In the former script, I had created a new problem of not finding the onload
handler; in the latter, things still behave in IE as though I were not testing
at all whether the sound is loaded.

Basically, the "stopped" frame of the movie contains a play button that I want
to hide until the sound is loaded. In another frame ("loading", after the
above code but before "stopped") I have this code:

caption = Math.floor(((mySample.getBytesLoaded() /
mySample.getBytesTotal())*100)) + "% loaded";

and in another frame I have a gotoandplay() that loops back to the "loading"
frame, theoretically infinitely until onLoad() fires.

I'm testing this locally two ways: one is by trying to load an enormous mp3
file, and the other is by specifying a filename that doesn't exist.
Theoretically, the second test should never result in onload() occurring. The
script works fine in other browsers, but (now that I've correctly ordered
onLoad() and load()) in IE the movie advances to the "stopped" frame right away.

If anyone is into into looking at my .fla that would rock....

Am I the only person in the universe who is noticing a discrepancy between
browsers?????

thanks again for the reply
Re: onLoad and getBytesLoaded() wierd in IE tralfaz
5/4/2005 9:35:35 PM
[quoted text, click to view]

I don't find any difference whether the onLoad event hander is defined
before or after the loadSound command. It works either way in IE and
Firefox. It's not going to get fired until much later anyway, after
the sound finishes loading (unless your cache still has the file in
it). (empty your cache every time while testing)

Here is test with onLoad handler code following the loadSound..
http://members.cox.net/4my5cats/loadmp3a.html
And here is same code but the onLoad hander code precedes the
loadSound function
http://members.cox.net/4my5cats/loadmp3.html

Here is the code I used.. small changes to what you had..

// frame 1 code
mySample = new Sound(this);
mySample.setVolume(75);
mySample.loadSound("sound2.mp3", false);
mySample.onLoad = function ()
{
gotoAndStop("stopped"); // label 'stopped' on frame 20
}

_root.onEnterFrame = function()
{
var gbt = mySample.getBytesTotal();
total.text = gbt;
var gbl = mySample.getBytesLoaded();
loaded.text = gbl;
var percentage = (gbl / gbt) * 100;
caption.text = Math.floor( percentage ) + "% loaded";
if(percentage == 100)
delete this.onEnterFrame;
}

// frame 6 code
gotoAndPlay(2);

HTH
tralfaz


Re: onLoad and getBytesLoaded() wierd in IE tralfaz
5/4/2005 9:51:25 PM
[quoted text, click to view]

hey again..
I was thinking about it just a bit more.. I really wouldn't use an
onLoad hander at all. It might not fire the 2nd time the page is
visited. I have had too many problems with onLoad in the past. Here
is the way I would write it..

// frame 1 code
mySample = new Sound(this);
mySample.setVolume(75);
mySample.loadSound("sound2.mp3", false);

_root.onEnterFrame = function()
{
var gbt = mySample.getBytesTotal();
total.text = gbt;
var gbl = mySample.getBytesLoaded();
loaded.text = gbl;
var percentage = (gbl / gbt) * 100;
caption.text = Math.floor( percentage ) + "% loaded";
if (gbt && (gbl >= gbt) )
{
delete this.onEnterFrame;
gotoAndStop("stopped"); // label 'stopped' on frame 20
}
}

// frame 6 code
gotoAndPlay(2);

Test here..
http://members.cox.net/4my5cats/loadmp3c.html

MX source code to that test page..
http://members.cox.net/4my5cats/loadmp3c.zip

tralfaz

Re: onLoad and getBytesLoaded() wierd in IE Blade al'Slayer
5/5/2005 12:00:00 AM
[quoted text, click to view]
Hi. I said the thing about placing the onLoad before loadSound, because
it is said so in the documentation! And it didn't work for me the other way.

--
Re: onLoad and getBytesLoaded() wierd in IE Blade al'Slayer
5/5/2005 12:00:00 AM
[quoted text, click to view]
E-mail me your .fla and I will look into it...

--
Re: onLoad and getBytesLoaded() wierd in IE tralfaz
5/5/2005 9:01:55 AM
[quoted text, click to view]

Yeah, I believe you. It might have some quirk, depending on which
player and which browser etc. That's why I don't think you should use
onLoad at all in that situation. Just compare the number of bytes
loaded to the total bytes and when it's equal, then play or whatever.
It will work again on repeat loads too, which onLoad might not.
later,
tralfaz

Re: onLoad and getBytesLoaded() wierd in IE spreenchy
5/6/2005 12:00:00 AM
Hey Trafalz,

I had the idea to use (mySample.getBytesLoaded() / mySample.getBytesTotal())
too. (Have another look at my first post.) In fact, I tried it before
originally posting to this newsgroup, figuring that once it reached 100% it
would do the trick. (Also I can implement a sort of progress indicator this
way.)

But again, the value for getBytesLoaded() seems to equal the value for
getBytesTotal() in Internet Exlorer BEFORE the file has loaded. That is, when
I test the script locally with an enormous mp3 file (and yes I'm clearing my
browsers' caches every time), there's this lovely ascending
perfectly-well-behaved percentage in Firefox and Mozilla, and a "100%" and an
mp3 that hasn't loaded in IE.

.......????? still stumped.........



Re: onLoad and getBytesLoaded() wierd in IE tralfaz
5/6/2005 9:28:54 PM
[quoted text, click to view]

Did you check for valid data before doing the comparison? For mp3
loading just check for non-zero values in getBytesTotal().
Look closely at this code..
if(gbt && (gbl >= gbt) )
{
gotoAndPlay(4);
}
The part that says " if(gbt " means if gbt is a non zero value,
then compare gbt to gbl
Actually I usually look for a minimum value of 100 bytes like this
code..

mc1.loadMovie("image1.jpg");

_root.onEnterFrame = function()
{
var gbt = mc1.getBytesTotal();
if(gbt < 100) // wait for min value
return;

var gbl = mc1.getBytesLoaded();

if (gbl >= gbt)
{
delete this.onEnterFrame;
gotoAndPlay(3);
}
}

There are some situations where comparing gbt to gbl results in a
match and preloader failure on different values..
1) loading into levels.. matching 'undefineds'
2) loading into empty movieclips..matching zeros
3) loading into a stage object.. matching 12 bytes (regardless of
object size)

hope that helps
tralfaz




AddThis Social Bookmark Button