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.

22 comments:

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!

Dave said...

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

Kurt said...

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

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.

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?

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?

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.

Russ said...

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

Claudio Midolo said...

thanks man, it helped me a lot!

Anonymous said...

thanks man, it was helpful

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.

Rossie said...

Your post helped me to solve the same problem after i went crazy from this error message :)

Thank you!

koreyKorey said...

OMG LOL ROFL,
Yes ...public class... too, perhaps code 1065 can be used as a social foepah fer "no public class" haahaahaaaa,.. its late sorry,

thanks for the Tip mang..

-Karnei

timk said...

Thank you so much. I wasted 2 hours trying to figure this out.

cwaidelich said...

LIVESAVER! First result in Google!

Please note: this is good Internet!!!

thx again dude.

Srđan Prodanović said...

Woah, what a dumb error message. Lost a couple of minutes troubleshooting this myself. Thanks to Google and you, I can carry on doing real work. Good call to put this in a blog post

dustin said...

thanks, I feel stupid for forgetting to declare the class public, but it would have taken my a long time to figure out what the problem was if it were not for your post.

Anonymous said...

Thanks for this you just saved me half an hour of pointless debugging.

Pepijn said...

Thanks for putting it up, I also forgot to make the class PUBLIC xD

nick said...

thanks, this helped alot

Simon said...

Yeah, just got bitten by this one. Got about 20-30 classes in my project. All the main ones seemed to be listed as "public", but a small minor one was missing the "public" statement and it caused an error for every single clip in my library and NOTHING would work.

It was a very frustrating 5 hours picking through various versions of my code! So check ALL your classes to make sure they're public! Hope this helps someone!

Simon.

Anonymous said...

thanks, worked for me :)

Post a Comment