I have a bug that has taken a giant amount of time to track down, and I'm thinking it 'might' come down to the fact that SetInterval doesn't seem to take anonymous functions. Hmm, well I'm not actually using anonymous functions, but it is the only behaviour that seems to be similar to what I'm (not) seeing, so I'm pursuing that at the moment...
This works, of course:
var cls = function(){}
cls.prototype.meth = function(){trace("call")};
inst = new cls();
setInterval(inst, "meth", 500);
And this does not work:
var cls = function(){}
cls.prototype.meth = function(){trace("call")};
setInterval(new cls(), "meth", 500);
Is this a known behaviour? I'd love any more info on this as to what is happening, and what is causing it to fail...
I have a point in the code where I have an obj, meth, and interval count (obj, string and int), I can call the method from there using obj[meth](). With that and traces, type check etc, I'm pretty sure they are valid. Then if I setInterval with them, it returns an interval id, but the method never gets called. If I use a static method (with no method name, the other overload of setInterval) it works. I have also been thinking it could be somehow not getting that overload properly, but the types seem right.
<Compliant> That is a really crazy overload imo, one is setInterval(object, int, args..) the other is setInterval( object, string, int, args...). Given the way swf freely converts between these types, it is very hard to nail down what is happening inside setInterval. </Compliant>
The third possibilty I've been looking at is that I'm using setInterval.apply(null, args) - at the bytecode level setInterval requires CallFunction, maybe it is somehow getting mixed up with this apply. I can use 'apply'from the flash IDE though, and can't seem to generate the same problem I'm seeing.
Last thing I'm thinking, (well first, just I've been over and over it : ) is I'm just doing somehting plain and simple wrong, and missed it. This is all from generated bytecode, but here is the reversed code from ASV (oh, love that program!):
_global._setInterval = function (delg, time)
{
var d = delg._delegates[0];
var args = [];
args.push(d.obj);
if (d.name != null)
{
args.push(d.name);
}
var i = 1;
while (i < arguments.length)
{
args.push(arguments[i]);
i++;
}
// TEST
args[0][args[1]](); // calls the method on the instance, no problem
trace (args[0]); // traces the instance object as [object], np
setInterval(args[0], "CheckVarsLoaded_9", 1000); // doesn't work
// also doesn't work (though rets interval ID)
return (setInterval.apply(null, args));
}
Any insights, similar issues, theories, legends, commentary, or outrageous comments you may have would be dearly appreciated : ).
Thanks!
posted on Monday, February 07, 2005 1:34 PM