Flex VerifyError: Error #1102

Posted on:October 15 2009

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.





Comments:


Actually using 0 instead of NULL is more common with C++ programmers than with C programmers. The definition is also slightly different:

#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".
Michi
Quote
2009-10-15 14:40:00


One of these mistakes you do not do anymore when also working with Java and/or C# ;)
Tazo
Quote
2009-10-15 14:43:00


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
Quote
2009-10-19 07:29:00


Add comment:


Posted by:


Enter the missing letter in: "?nternational"


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons