1

I hope someone can help with this. I've got a strange error coming up in Firebug on my page.

I'm using the code:

$(function () {
var element = $("#finger");
(function(){
    element
        .animate({ marginLeft: 130 }, 1000)
        .animate({ marginLeft: 100 },   1000 , arguments.callee);
}());
});

This works fine to animate my 'finger'.

I also have this other code:

$("SOME-OTHER-DIV").mousedown(function () { 
  $("#finger").hide(); 
});

This makes my 'finger' hide when clicked on.

Now, this all works fine.... up until the point when I reload the page whereby I get this error

"attempt to run compile-and-go script on a cleared scope"

Yet, the animation still works, and the mousedown also still works.

Any ideas what's going on here? Is it just a bug in Firefox? Many thanks in advance Chris

----------update---------

Hmm, perhaps it's not the "arguments.callee" that's causing the problem. I changed the code to:

$(function () {
i = 0;
while(i < 3){
$("#finger").animate({ marginLeft: 130 }, 1000).animate({ marginLeft: 100 },   1000);
i++;
}
});

Which loops through 3 times (ok, not infinite, but it's just for example) and I still get the "attempt to run compile-and-go script on a cleared scope" error on page reload in Firebug :-S

Chris
  • 73
  • 3
  • 9

3 Answers3

2

This seems to be an issue with FF4. See this and this. As the other thread says try clearing the cache.

Try this code and check if you still get the error - demo

$(function() {
    animateFinger();
});

$("#abc").mousedown(function() {
    $("#finger").toggle("display");
});

function animateFinger() {
    $("#finger").animate({
        marginLeft: 130
    }, 1000).animate({
        marginLeft: 0
    }, 1000, animateFinger);
}

If that doesn't work try using setInterval and calling the method every 2000 milliseconds - demo

$(function() {
    animateFinger();
    setInterval(animateFinger, 2000);
    // You can also try function(){setTimeout(animateFinger, 0)} as a callback method instead of setInterval
});

$("#abc").mousedown(function() {
    $("#finger").toggle("display");
});

function animateFinger() {
    $("#finger").animate({
        marginLeft: 130
    }, 1000).animate({
        marginLeft: 0
    }, 1000);
}

All the best in your finger pointing business. ;)

Community
  • 1
  • 1
Praveen Lobo
  • 6,956
  • 2
  • 28
  • 40
  • Thanks for this code, absolutely awesome. Works a treat for animating the finger indefinitely. However after having tried all these options I am sorry to have to say that it still produces the same error on reload. – Chris Jun 26 '11 at 10:16
1

I think that arguments.callee may be the cause. I think that does some funky trickery that not all JS engines fully support.

Alex Wayne
  • 178,991
  • 47
  • 309
  • 337
  • Yes seems to be "arguments.callee" that's causing the problem. Is there any other way of looping this animation without using "arguments.callee"? – Chris Jun 25 '11 at 09:49
-3

It's Firefox. If you disable the cache the error probably won't pop up.

In about:config set:

network.http.use-cache = false
orkutWasNotSoBad
  • 638
  • 6
  • 12