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?
Unfortnately, it's wrong and will cause this 'VerfiyError' when running the SWF. The correct version would be
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.
three comments, already:
Actually using 0 instead of NULL is more common with C++ programmers than with C programmers. The definition is also slightly different:
#define NULL 0
#define NULL ((void*)0)
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”.
Michi - 15 10 09 - 14:40
One of these mistakes you do not do anymore when also working with Java and/or C#
Tazo - 15 10 09 - 14:43
I don’t like that strict type checking in Java (though I normally use “NULL”. Just got used to the weakness of the C-checking from the very beginning of programming.
Brainsaw (link) - 19 10 09 - 07:29