« This is the end | Main | Flex 2 Runtime Error 1009 and Runtime Modules »

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.

Tags: actionscript as3 flex programming

Comments

Thanks for this tip! I was struggling with the same problem and it seems to work now. Enrique.
The most common cause is not declaring a class which is linked to a movie clip as public. Here is more on the issue.
Thanks Daniel! It was indeed very helpful.
Thankyou Enrique Rodriguez ! That's something that people new to as3 OOP maynot have noticed. It's often the simple things! Classes need to be public if they are providing the base for a symbol in the library. Cheers! Hoecus-Poke-us
Error just started popping up, was fixed by using your tips :) Thanks!
Thanks for that - that helped!
Damn, you're right! I was spending days around this problem. This is a bug, because the import statements should clarify which classes are known in the app.
Few weeks ago I was desperately looking for how to dynamically instantiate classes in AS3 but I was unable to find any resource on this, but fortunately today i was searching for 'flash Error #1065:', and I found what I was looking for weeks. Thanks a TON !

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)



About