Search code examples
actionscript-3flasherror-handling

Is there an ActionScript 3 error 1046 handler?


I'm talking about this error:

ERROR 1046: Type was not found or was not a compile-time constant: CustomType

Where CustomType is defined in a class in an .as file. I know you need to import that file in order to avoid this error, but my question is, is there any error handler for this error?

I mean, is there a way to say, for example:

onErrorHandler {
  trace("You need to import the class!");
} else {
  private var myObject:CustomType;
}

Solution

  • That error is a thrown at compile time, so no.

    The import statement tells Flash what classes need to be compiled for your current class to function as expected. You can't write code to catch an error that is thrown at compile-time, because it doesn't compile and thus doesn't get executed.

    It is the compiler's responsibility to catch these errors, not yours.