Flex 2 Runtime Error 1065
Today while working on some code I started getting this error and stack trace:
ReferenceError: Error #1065: Variable LoadTest is not defined.
at global/flash.utils::getDefinitionByName()
at ... (rest of stack trace deleted)
Looking the error up in the documentation didn't help point the way to what might be going on since this had nothing to do with a "variable":
1065 Variable _ is not defined. You are using an undefined lexical reference. For example, in the following statements, the statement trace(x) generates an error because x is undefined. However, the statement trace(y) doesn't generate an error because y is defined: trace("hello world") trace(x) // x is undefined var y trace(y) // No error, y is defined.
In this case I was trying to dynamically instantiate a class by first finding the definition of that class and then newing it. Something like this:
public function createInstance(className:String):Object {
var instance:Class = Class(getDefinitionByName(className));
new instance();
}
It turns out the reason why the error was being thrown was that in my Flex Application I didn't have anything which "used" the class. In other words the compiler thought that the class was left over junk and didn't include it in the compiled swf. By adding in a use of it, everything started working. As example use would be something like:
private static const loadTestRef:LoadTest = null;
If there is another way to get this same behavior, please let me know.
Comments
Posted by: Enrique Rodriguez | August 25, 2006 8:49 AM
Posted by: Andrew Paul Simmons | June 7, 2007 11:37 AM
Posted by: Bijit Bose | June 22, 2007 9:04 AM
Posted by: Ben Hoe | September 4, 2007 5:01 AM
Posted by: Bram | November 6, 2007 9:07 AM
Posted by: Judit | February 13, 2008 9:13 AM
Posted by: Chris | May 6, 2008 12:25 PM
Posted by: Mudit Tuli | August 25, 2008 2:51 AM