Today the flash .swf I was working on simply stopped working, and I had no idea what was wrong. Fortunately, when using the debug Flash VM, it wrote "VerifyError: Error #1102: Illegal default value for type" or "VerifyError: Error #1102: Unzulässiger Standardwert für Typ" in my case (having the german version).
It took me a bit to find the code causing the problem, but finally I did, and it wasn't that obvious. Take this code for example, looks quite ok, doesn't it?
private function foo(a:SomeType=0):void{ // implementation here}
Unfortnately, it's wrong and will cause this 'VerfiyError' when running the SWF. The correct version would be
private function foo(a:SomeType=null):void{ // implementation here}
As it turns out, the ActionScript 3 compiler of Flex has a strange 'feature': You obviously can set default values for parameters as you like.
The problem: When the Flash VM comes to this function and the types don't match, it will simply stop or throw an exception. Setting '0' instead of 'null' is common for C and C++ programmers, but for Actionscript 3, '0' is an int or a Number, and null is the null reference.
The strange part is that the flex compiler doesn't write an error or at least a warning for this and produces a SWF file with corrupt AS3 bytecode.
#ifdef __cplusplus
#define NULL 0
#else
#define NULL ((void*)0)
#endif
So basically, 0 and NULL are the same only in C++ (in C they are exchangeable because of the weak type system though). In my experience "pure" C programs normally use NULL, which is the better practice IMHO. After all, a pointer to the memory address "0" is something completely different than an integer with the value "0".