Resolve Flex’s error: “Type was not found or was not a compile-time constant”

I just faced the terrible nightmare of “Type was not found or was not a compile-time constant” error (Flex Builder) and I lost several time to figure out what the problem was.
I realized that I was using the same name for MXML Application file which was already used by a class inside one of my packages. So, by renaming the file I solved the problem, but I was not completely satisfied and I looked for a way to avoid the error mantaining the same file/class name. Initially I tried to use namespaces, but as the reference says: “Applying a namespace means placing a definition into a namespace. Definitions that can be placed into namespaces include functions, variables, and constants (you cannot place a class into a custom namespace)”. I finally solved by renaming class references inside my package with the full qualified name (from MyClass to com.mysite.foo.MyClass)

  • kepica

    thank you a lot. it realy helps ! this is such a headeacke :( someone made a funny post – hope steve jobs will kill flash ! :-) after reading this tip it is so trivial. WHY ADOBE DON’T HAS THIS TIP IN FLEX HELP !?!!!!

  • Theo

    Hi I had the same symptoms “Type was not found or was not a compile-time constant”. Took a while to figure out. When control clicking the class it took me right to the class and the import statement was correct. I noticed eventually that the filename did not exactly match the class name. I had the class TaskSpecFormEvent in the file TasksSpecFormEvent.as (extra ‘s’ on task).

    So watch out for this too.

  • Thanks a lot…it saved me from horrible headache.. :D

    Hi I had the same symptoms “Type was not found or was not a compile-time constant”. Took a while to figure out. When control clicking the class it took me right to the class and the import statement was correct. I noticed eventually that the filename did not exactly match the class name. I had the class TaskSpecFormEvent in the file TasksSpecFormEvent.as (extra ‘s’ on task).

    So watch out for this too.

    Thanks for this reply…

  • amit

    i am trying to use mx:HTML and will using only if it is air application but getting this air while compiling (mx.controls:HTML):[-1,-1] Type was not found or was not a compile-time constant: HTMLHost.