By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,473 Members | 1,267 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,473 IT Pros & Developers. It's quick & easy.

animated gif stops when doing cpu intensive task

P: n/a
Hi,
I have the following code that shows up a div with an animated gif
inside, executes a cpu intensive function using setTimeout and then
hide the div again:

getEl('divWaiting').style.display = 'block';
window.setTimeout(function(){me.FM.addFlagPopBox(m e);
getEl('divWaiting').style.display = 'none';}, 1000);

issue is that the animated gif will stop as soon as the function in
setTimeout starts. How can I solve this ?

Thanks

ps: me is a global variable that refers to this object.

Jul 24 '06 #1
Share this Question
Share on Google+
10 Replies


P: n/a
sa*************@googlemail.com wrote:
Hi,
I have the following code that shows up a div with an animated gif
inside, executes a cpu intensive function using setTimeout and then
hide the div again:

getEl('divWaiting').style.display = 'block';
window.setTimeout(function(){me.FM.addFlagPopBox(m e);
I think you made a triple mistake here:
window.setTimeout(function(){me.FM.addFlagPopBox(m e);

1) it is missing the }
2) it is also missing the number of milliseconds before executing the
function.
3) The first argument should be a string to be executed, not a reference to
an anonymous function.

So try something like:
setTimeout("FM.addFlagPopBox(me);",100);

where you are responsible to make a function with that name of course that
handles whatever it is you are trying to accomplish.

Didn't you get an errormessage on that line?
If so, you are probably using IE for development, which is a poor choiche
compared to Firefox and the likes. The latter has a javascriptconsole which
will give you detailed errormessages.

Hope that helps.
Regards,
Erwin Moller
getEl('divWaiting').style.display = 'none';}, 1000);

issue is that the animated gif will stop as soon as the function in
setTimeout starts. How can I solve this ?

Thanks

ps: me is a global variable that refers to this object.
Jul 24 '06 #2

P: n/a
Hi Erwin,
Sorry I completely messed up when I pasted my code in the forum :(
My code is correct and I have no errors:

getEl('divExpandedFlags').style.display = 'block';
this.CloseButton =
getChildElement(getChildElement(getEl('divExpanded Flags'),
'divExpandedFlagsHeader'), 'divExpandedFlagsClose');

getEl is a function that do the same as getElementById.

Anyway, the issue is in my first post.

Sam

Erwin Moller wrote:
sa*************@googlemail.com wrote:
Hi,
I have the following code that shows up a div with an animated gif
inside, executes a cpu intensive function using setTimeout and then
hide the div again:

getEl('divWaiting').style.display = 'block';
window.setTimeout(function(){me.FM.addFlagPopBox(m e);

I think you made a triple mistake here:
window.setTimeout(function(){me.FM.addFlagPopBox(m e);

1) it is missing the }
2) it is also missing the number of milliseconds before executing the
function.
3) The first argument should be a string to be executed, not a reference to
an anonymous function.

So try something like:
setTimeout("FM.addFlagPopBox(me);",100);

where you are responsible to make a function with that name of course that
handles whatever it is you are trying to accomplish.

Didn't you get an errormessage on that line?
If so, you are probably using IE for development, which is a poor choiche
compared to Firefox and the likes. The latter has a javascriptconsole which
will give you detailed errormessages.

Hope that helps.
Regards,
Erwin Moller
getEl('divWaiting').style.display = 'none';}, 1000);

issue is that the animated gif will stop as soon as the function in
setTimeout starts. How can I solve this ?

Thanks

ps: me is a global variable that refers to this object.
Jul 24 '06 #3

P: n/a
argggggg what am i doing, i pasted wrong code again. The code I pasted
in the first post was correct, it was split up on two lines by the
editor but it should be read as one line, look again.
samuelberthe...@googlemail.com wrote:
Hi Erwin,
Sorry I completely messed up when I pasted my code in the forum :(
My code is correct and I have no errors:

getEl('divExpandedFlags').style.display = 'block';
this.CloseButton =
getChildElement(getChildElement(getEl('divExpanded Flags'),
'divExpandedFlagsHeader'), 'divExpandedFlagsClose');

getEl is a function that do the same as getElementById.

Anyway, the issue is in my first post.

Sam

Erwin Moller wrote:
sa*************@googlemail.com wrote:
Hi,
I have the following code that shows up a div with an animated gif
inside, executes a cpu intensive function using setTimeout and then
hide the div again:
>
getEl('divWaiting').style.display = 'block';
window.setTimeout(function(){me.FM.addFlagPopBox(m e);
I think you made a triple mistake here:
window.setTimeout(function(){me.FM.addFlagPopBox(m e);

1) it is missing the }
2) it is also missing the number of milliseconds before executing the
function.
3) The first argument should be a string to be executed, not a reference to
an anonymous function.

So try something like:
setTimeout("FM.addFlagPopBox(me);",100);

where you are responsible to make a function with that name of course that
handles whatever it is you are trying to accomplish.

Didn't you get an errormessage on that line?
If so, you are probably using IE for development, which is a poor choiche
compared to Firefox and the likes. The latter has a javascriptconsole which
will give you detailed errormessages.

Hope that helps.
Regards,
Erwin Moller
getEl('divWaiting').style.display = 'none';}, 1000);
>
issue is that the animated gif will stop as soon as the function in
setTimeout starts. How can I solve this ?
>
Thanks
>
ps: me is a global variable that refers to this object.
Jul 24 '06 #4

P: n/a
sa*************@googlemail.com wrote:
argggggg what am i doing, i pasted wrong code again. The code I pasted
in the first post was correct, it was split up on two lines by the
editor but it should be read as one line, look again.
Hi,

Nevermind, if you live in Europe you are probably desintegrating because of
the heat just like me. ;-)

Still, here is your original code:

getEl('divWaiting').style.display = 'block';
window.setTimeout(function(){me.FM.addFlagPopBox(m e);
getEl('divWaiting').style.display = 'none';}, 1000);

This indeed solves my comment 1 and 2, but 3 still stands:
"The first argument should be a string to be executed, not a reference to an
anonymous function."

You are still not passing a string to setTimeout.
You should call it like this: setTimeout("STRING HERE", 1000);

And again: Why didn't you see an error?

So this has little to do with high CPU load, but with an invalid call to
setTimeout().

I am unsure if you can pass an Objectreferences to a setTimeout function.
I always avoid such situations anyway by simply calling a function with a
string-parameter, or an integer, that handles the whole shebang.
Like this:
setTimeout("doFlagPopBoxStuff('me');", 1000);

and in doFlagPopBoxStuff you make sure you make a valid reference to your
me-object. Then do your stuff with it.

The reason I warn you about this is simply that when the 1000 millies pass,
your reference can be invalid (eg a removed form-element).

Hope that helps,

Regards,
Erwin Moller
>

samuelberthe...@googlemail.com wrote:
>Hi Erwin,
Sorry I completely messed up when I pasted my code in the forum :(
My code is correct and I have no errors:

getEl('divExpandedFlags').style.display = 'block';
this.CloseButton =
getChildElement(getChildElement(getEl('divExpande dFlags'),
'divExpandedFlagsHeader'), 'divExpandedFlagsClose');

getEl is a function that do the same as getElementById.

Anyway, the issue is in my first post.

Sam

Erwin Moller wrote:
sa*************@googlemail.com wrote:

Hi,
I have the following code that shows up a div with an animated gif
inside, executes a cpu intensive function using setTimeout and then
hide the div again:

getEl('divWaiting').style.display = 'block';
window.setTimeout(function(){me.FM.addFlagPopBox(m e);

I think you made a triple mistake here:
window.setTimeout(function(){me.FM.addFlagPopBox(m e);

1) it is missing the }
2) it is also missing the number of milliseconds before executing the
function.
3) The first argument should be a string to be executed, not a
reference to an anonymous function.

So try something like:
setTimeout("FM.addFlagPopBox(me);",100);

where you are responsible to make a function with that name of course
that handles whatever it is you are trying to accomplish.

Didn't you get an errormessage on that line?
If so, you are probably using IE for development, which is a poor
choiche compared to Firefox and the likes. The latter has a
javascriptconsole which will give you detailed errormessages.

Hope that helps.
Regards,
Erwin Moller

getEl('divWaiting').style.display = 'none';}, 1000);

issue is that the animated gif will stop as soon as the function in
setTimeout starts. How can I solve this ?

Thanks

ps: me is a global variable that refers to this object.
Jul 24 '06 #5

P: n/a
Erwin Moller wrote:
<snip>
This indeed solves my comment 1 and 2, but 3 still stands:
"The first argument should be a string to be executed, not a reference
to an anonymous function."
This is not true, at least from IE 4, Netscape 4, opera 6 and many
others. A function reference may be the first argument to setTimeout,
Indeed it can be argued that a function reference is a better argument
to use, partly because it can be executed faster (not needing
interpreting into code) and partly because a string object can be
provide with a custom toString method that would return a string that
effectively called the function, providing optimum performance plus
full backward compatibility with older setTimeout implementations that
only accept string arguments.
You are still not passing a string to setTimeout.
You should call it like this: setTimeout("STRING HERE", 1000);

And again: Why didn't you see an error?
<snip>

Even on an implementation that only accepts string arguments the effect
of passing a function reference would be expected to be implicit
type-conversion of the function to a string, and as toString methods of
functions objects traditionally return the function's source code (more
or less) the string executed by the timeout would be a string of
javascript code that defined a function. No error would be expected
when this was executed, although no actual effects would be expected
either.

Richard.

Jul 24 '06 #6

P: n/a
Nevermind, if you live in Europe you are probably desintegrating because of
the heat just like me. ;-)
It's bloody hot indeed .. :)

As Richard said, it works for me... No error at all, whether with IE or
FF. That bit of code works just fine. Actually as I keep saying there
is nothing wrong with my code. However, it should be modified to
accommodate new requirement, which is allowing the gif to animate even
when the cpu intensive task is being executed. And THAT is my problem
:)
Anyone knows how I could do that ?

cheers,
Sam

Jul 24 '06 #7

P: n/a
Richard Cornford wrote:
Erwin Moller wrote:
<snip>
>This indeed solves my comment 1 and 2, but 3 still stands:
"The first argument should be a string to be executed, not a reference
to an anonymous function."

This is not true, at least from IE 4, Netscape 4, opera 6 and many
others. A function reference may be the first argument to setTimeout,
Indeed it can be argued that a function reference is a better argument
to use, partly because it can be executed faster (not needing
interpreting into code) and partly because a string object can be
provide with a custom toString method that would return a string that
effectively called the function, providing optimum performance plus
full backward compatibility with older setTimeout implementations that
only accept string arguments.
Hi Richard,

Maybe that is true, maybe not.
My wisdom comes from O'Reilly's "Javascript, the definitive Guide, 4th
edition, covers Javascript 1.5".
It states clearly it want a string (page 679), no notes about a
functionreference whatsoever.

So I won't ague that you are wrong, I just want to note that is not
described in 'the guide'.

>
>You are still not passing a string to setTimeout.
You should call it like this: setTimeout("STRING HERE", 1000);

And again: Why didn't you see an error?
<snip>

Even on an implementation that only accepts string arguments the effect
of passing a function reference would be expected to be implicit
type-conversion of the function to a string, and as toString methods of
functions objects traditionally return the function's source code (more
or less) the string executed by the timeout would be a string of
javascript code that defined a function. No error would be expected
when this was executed, although no actual effects would be expected
either.
Aha, that clears that mystery up then!

Is this the same reason you can pass a function-reference to setTimeout?
Becuase it is converted via toString() to (a copy of?) the original
function?

Thanks for the explanation.

Regards,
Erwin Moller

>
Richard.
Jul 24 '06 #8

P: n/a
Erwin Moller wrote:
Richard Cornford wrote:
>Erwin Moller wrote:
<snip>
>>"The first argument should be a string to be executed, not a reference
to an anonymous function."

This is not true, ...
<snip>
Maybe that is true, maybe not.
My wisdom comes from O'Reilly's "Javascript, the definitive Guide, 4th
edition, covers Javascript 1.5".
It states clearly it want a string (page 679), no notes about a
functionreference whatsoever.

So I won't ague that you are wrong, I just want to note that
is not described in 'the guide'.
The "definitive guide" is only the least bad javascript book available,
that doesn't meant it is good, comprehensive, accurate, wise or
definitive.

<snip>
>Even on an implementation that only accepts string arguments the effect
of passing a function reference would be expected to be implicit
type-conversion of the function to a string, and as toString methods of
functions objects traditionally return the function's source code (more
or less) the string executed by the timeout would be a string of
javascript code that defined a function. No error would be expected
when this was executed, although no actual effects would be expected
either.

Aha, that clears that mystery up then!

Is this the same reason you can pass a function-reference to setTimeout?
Becuase it is converted via toString() to (a copy of?) the original
function?
<snip>

No, the source code for a function declaration or a function expression
will be just a function declaration or a function expression; you need
call operators in addition to actually execute them.

Richard.

Jul 24 '06 #9

P: n/a
Erwin Moller <si******************************************@spam yourself.comwrites:

[function parameter to setTimeout/setInterval]
My wisdom comes from O'Reilly's "Javascript, the definitive Guide, 4th
edition, covers Javascript 1.5".
It states clearly it want a string (page 679), no notes about a
functionreference whatsoever.
It's just a reference book, not the definition.
For authoritative definitions by the people actually implementing setTimeout,
see:
<URL:http://developer.mozilla.org/en/docs/DOM:window.setTimeout>
<URL:http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/settimeout.asp>

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 24 '06 #10

P: n/a
Nevermind, if you live in Europe you are probably desintegrating because
of
the heat just like me. ;-)
No no... not desintegrating ... I'm slowly being cooked.
Jul 24 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.