Error #1065: Variable XYZ is not defined. at global/flash.utils::getDefinitionByName()

ReferenceError: Error #1065: Variable B is not defined.
   at global/flash.utils::getDefinitionByName()
   at nz.co.codec.flexorm::EntityIntrospector/getClass()[/nz/co/codec/flexorm/EntityIntrospector.as:1300]

It's not a bug it's a feature ;) The problem here is the SWF compiler in Flex Builder is optimizing out any imports that don’t get instantiated, so at run-time, the class really doesn’t exist in the SWF.

Basically when you try to use a class that you have included in your SWC using //getDefinitionByName(“MyClassName”) as Class//, the compiler throws an error message saying it can’t find them – variable not defined etc. Even though you think that those classes are in your SWC and therefore in your project, the compiler still doesn’t know about them so you need to tell it to include them when compiling.


There are several ways to achieve this. The most basic way is just to reference them in your code. Even a trace(MyClass) message will work or defining a dummy variable like var foo:MyClass;. The problem with this method is that you have to write a lot of dummy code to include a bunch of classes. There's another (dirty) workaround for now to use the EntityIntrospector and preload the class metadata before loading the list of As: em.introspector.loadMetadata(MyClassName);

Flash Develop

The correct way to do it in FD is actually to add the SWC that the class is in to the project via //Project Properties > Compiler Options > SWC Include Libraries// list. This way all classes in the SWC you specify are compiled.

However the problem with this method is that this it includes ALL the classes in that SWC you define.

Flash Builder

The correct way to do it in FB is to add compiler flags via //Project > Properties > Flex Compiler > Additional compiler arguments// and to add the class or whole library. Same as above.

includes class [...]
include-libraries library [...]



Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.