ASVDrawing example
This guy has been experimenting with ASV and my ASVDrawing class. He's also used it for the background effect on his main page, where the background builds up as if it is being drawn.
ecma4-style runtime strong typing
It's kind of silly really, but I found that you can use a colon ( : ) as a character in the name of an identifier when you declare it. This lets you write syntax that looks like an ecma4 typed variable:
var myNum:Number = 2;
Of course it doesn't work. In fact this doesn't even create a variable at all, as you will find if you look in the debugger. However, I found an exception where you declare the property as a function parameter:
function myFunction (arg:Array) {
//
}
You can now reach the variable through the arguments array. You still cannot access the variable arg directly but, if you check the debugger, you will see that there is a local variable called "arg:Array". But try and access that with AS! You'd probably try eval first, as I did, but that won't work because the colon has a special meaning in an evaluated string, because of its deprecated Flash4 usage. The only other angle of attack would be to somehow use the Array access operator ( [ ] ), but there isn't a containing object to apply it to...
...Well, actually there is! You can exploit a bug of the Flash player, which means that functions declared inside another one can refer to the outer function's activation object using this. The activation object of a function call is an object containing all the variables that were available to that function during the call, and it isn't supposed to be accessible by ActionScript.
So what can you do with this? I don't think there is much that is actually useful, but I came up with a little script that lets you emulate the ecma4 syntax and check the types or Classes of any vars passed into your function and generate an error message if any of them don't match up. Here's a demo:
function myFunction (a:Array, n:Number, s:String){
#include "runtimeStrongTypeCheck.as"
trace("a = " + a);
trace("n = " + n);
trace("s = " + s);
}
debugging with a Parasite...
The more I think about it, the more I think that the Parasite is the most useful bit of code I have ever written. I keep finding more and more applications.
This time its as a debugging tool. Parasite can be used to detect if a method has been called and what parameters were passed, just as it would detect that an event has been triggered, because its exactly the same process. That means I can trace out al the args that were passed in a function call, without having to edit the original code of that function.
#include "Parasite.as"
// class to be debugged
#include "BuggyClass.as"
myInstance = new BuggyClass();
// Parasite to catch the method calls
debugPara = Parasite.addParasite(myInstance, "myMethod");
// main debug object
debugObj = {};
debugPara.addListener(debugObj);
// invoked whenever myMethod is called in myInstance
debugObj.myMethod = function () {
trace ("myfunction called with args:
" + arguments);
}
