Wednesday, June 6, 2007

ReferenceError: Error #1065: Variable SimpleMP3Player is not defined.

I needed to make a simple flash mp3 player in about two hours today. I quickly setup my classes, launched my application, and this is the error that I got:

ReferenceError: Error #1065: Variable SimpleMP3Player is not defined.

I had set the linkage, in the linkage properties, of a symbol to point to the class SimpleMP3Player.

The class was written as follows:
package
{
import flash.display.*;
class SimpleMP3Player extends MovieClip
{

function SimpleMP3Player()
{
trace("MP3 Player instantiated");
}
}
}

I checked the adobe live docs and read:

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.

It didn't take too long to see that I had simply forgotten to declare the class SimpleMP3Player as public. Nevertheless, there could have been a much better error for this. When you take your compiler classes, they always teach you to include common errors in your parser so you can provide useful error messages. Apparently the Adobe AS3 developers weren't paying attention.

11 Comments:

Blogger Jared said...

This happened to me today. I was going nuts trying to figure out where I went wrong until I came across your post. Thanks!

June 17, 2007 9:17 PM  
Anonymous Dave said...

Thank you. Your explanation was spot-on, unlike Adobe's.

June 27, 2007 7:25 AM  
Anonymous Kurt said...

Good call on the public class thing. I was battling this error for the longest time!

August 8, 2007 5:14 AM  
Anonymous negush said...

Thanks for this post. I know I have to declare my classes as public, but today, I just forgot. Good thing I came across your post.

August 22, 2007 6:13 AM  
Anonymous Jeremy said...

I've got the same error popping up on two machines. The strange part is that two weeks ago when I put the project on hold everything was working perfectly. Secondly, I am receiving this error for mx.containers::Grid. This is especially weird because I'm creating the Grid component in MXML. Any thoughts as to why?

September 11, 2007 11:34 AM  
Anonymous Anonymous said...

Hi there, and thanks for your post. Not much information in regards to this out there...

I however get this errer regardsless of what I'm trying to do. Really annoying. Even though I don't have any variables in my class (just to check), I get this cryptic message. Any suggestions?

September 12, 2007 12:07 AM  
Anonymous Steve Jones said...

Just joining in on the thanks list - I'm rebuilding my AS2 site in AS3 and fell down on the Document Class immediately because I forgot the magic word "public". Thanks for the simple solution, and best of luck.

September 12, 2007 3:28 PM  
Blogger Russ said...

Thank you very much for posting this. You just helped me solve the exact same problem! public class... *grumble* :)

September 16, 2008 6:51 PM  
Blogger Claudio Midolo said...

thanks man, it helped me a lot!

September 28, 2008 3:54 PM  
Anonymous Anonymous said...

thanks man, it was helpful

September 28, 2008 3:54 PM  
Anonymous Anonymous said...

I read this solution but still didn't get it at first for some reason. I had made the constructor public and thought that was it. But of course you actually have to make the class public.

If you're still having problems, maybe you are actually getting the error because of the example in the Adobe description, which is using a variable without declaring it.

October 7, 2008 6:17 PM  

Post a Comment

<< Home