Friday, April 3, 2009

VerifyError 1102

VerifyError: Error #1102: Illegal default value for type * If you ever get this rather unusual run-time error, here's what to do. If you are using default values for arguments in a method's declaration part, make sure that the types match well. For instance, I wanted to explicitly call an event handler from the code and hence used null as the default value for the event parameter - only I typed it false instead of null (yeah, its Friday evening here). I don't know why the compiler thinks its okay to assign false (or a String or AnyThing) to an Event variable. private function init(e:Event = false):void So check your code for something silly like this, fix it and you are good to go. This run-time error is strange because livedocs says that "The VerifyError class represents an error that occurs when a malformed or corrupted SWF file is encountered". So you conclude that the SWF is having its issues on the Friday evening and rebuild the project to fix it. But no matter what you do to fix the "corrupted" SWF, you will get the same error again and again. Also, Flex doesn't show the corresponding MXML/AS file name or the line of code that caused this error, which it normally does with errors. It in fact traces the call stack, but that's not quite useful. One would normally expect the bug to be in the top most method of the call stack or in a method called from that. But here it seems that the top most method in the stack trace is the method that accesses any method/property from the buggy class for the first time in application. Adobe's documentation on Flex run-time errors says that "ActionScript in the SWF is invalid. If you believe that the file has not been corrupted, please report the problem to Adobe." - not really helpful either. But fortunately this is not even a run-time error - or this wouldn't have been one, had the compiler done its job well. And it turns out that the error message - Illegal default value for type * - is in fact correct. Compiler will detect wrong assignments in the case of basic types. For instance, if it was function(t:String = 3) you will get a compiler error 1184: Incompatible default value of type int where String is expected along with file name and the exact line of code that went wrong. But if its anything other than basic types, compiler just ignores it and you get this scary "malformed SWF". Hope this helps someone.
Links added with LinkIt


  1. Hope its time to update documents accordingly

  2. Yeah it helped a great deal.
    Thanks a bunch. The Flash IDE was crashing everytime I tried running the compiled SWF. Drove me crazy.

  3. Thanks for the tip. Made it clearer about where the real error was.

  4. I don't get why Flex won't return the line number or the location from where the error is occurring? So frustrating, I feel like I'm back in AS2 land!

  5. Are you guys by any chance using SWC libraries? I think that might be the source of the problem...

  6. Thanks a lot, I had this problem also. I did the same thing onEvent(e:Event=false)... It's such a simple mistake yet I probably never would have figured it.

  7. If you're actually using type * for your parameter(s), one quick workaround is to use *undefined* instead of *null* as your default value.

    For example, this will trigger the runtime error:

    function foo(param:* = null) {}

    But this is OK:

    function foo(param:* = undefined) {}

  8. Thank you Thank you, I was going around in circles trying to figure this out, I even tried looking in completely different classes because it errored only when I referenced a public static string.

    Think the error needs to say "Could Not Convert __AS3:Vec__ to Booleon.