macromedia flash actionscript scripting, php, remoting, webservices, c#, javascript
Sometimes you need to know which methods of an
object called in which order, here is a function that
do this job.
traceMessages = function (pObj, pBlnLastMethodOnly) {
for (var p in pObj) {
if (typeof pObj[p] != 'function') continue;
var tmp = pObj[p];
pObj[p] = function() {
var t = getTimer() - arguments.callee.__traceMessages.intLastCallTime;
arguments.callee.__traceMessages.intLastCallTime = getTimer();
trace('<call-of ['+t+']> ' + arguments.callee.__methodName + '(' + arguments.join(', ') + ')');
return arguments.callee.__originalMethod.apply(this, arguments);
}
pObj[p].__methodName = p;
pObj[p].__originalMethod = tmp;
pObj[p].__traceMessages = arguments.callee;
if (pBlnLastMethodOnly) return '';
}
return '';
}
// example:
// ========
CarClass = function () {
}
CarClass.prototype.init = function () {
this.turnEngineOn();
}
CarClass.prototype.turnEngineOn = function () {
trace('brum brum...');
}
objCar = new CarClass();
traceMessages(objCar); // <--
objCar.init();
// output:
// =======
// <call-of [38]> init()
// <call-of [0]> turnEngineOn()
// brum brum...
Posted by hOk at April 4, 2003 01:53 PM
Comments (2)
does this trace all the methods of an object?
'for (var p in pObj)' seems to find all 'thing' in pObj. i'm a new babe of the advanced flashcoder, and found that your blog is specific with the codes and useful stuffs. i will regularly check out ur blog to learn more and more ;)
Posted by jepezi at May 1, 2003 06:58 AM
Thanks, yes it should find
all methods of an object, but
traces them only when they called.
An collegue told me, that he got
an 256-recursion-error while using
this method with an inheritted-class.
I think he used the super-statement
and then inconsistences with this
method can ocure.
regards, Holger
Posted by at May 1, 2003 11:20 AM
|
You can use <code>code that should be highlightned</code> to highlight code! Optionally you can use the attribut language="php|perl|java" within the code tag, otherwise actionscript-highlightning will be used. |
