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:

  1. This happened to me today. I was going nuts trying to figure out where I went wrong until I came across your post. Thanks!
    ReplyDelete
  2. Thank you. Your explanation was spot-on, unlike Adobe's.
    ReplyDelete
  3. Good call on the public class thing. I was battling this error for the longest time!
    ReplyDelete
  4. 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.
    ReplyDelete
  5. 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?
    ReplyDelete
  6. 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?
    ReplyDelete
  7. 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.
    ReplyDelete
  8. Thank you very much for posting this. You just helped me solve the exact same problem! public class... *grumble* :)
    ReplyDelete
  9. thanks man, it helped me a lot!
    ReplyDelete
  10. thanks man, it was helpful
    ReplyDelete
  11. 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.
    ReplyDelete
  12. Your post helped me to solve the same problem after i went crazy from this error message :)

    Thank you!
    ReplyDelete
  13. 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
    ReplyDelete
  14. Thank you so much. I wasted 2 hours trying to figure this out.
    ReplyDelete
  15. LIVESAVER! First result in Google!

    Please note: this is good Internet!!!

    thx again dude.
    ReplyDelete
  16. Srđan ProdanovićSep 12, 2009 12:02 PM
    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
    ReplyDelete
  17. 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.
    ReplyDelete
  18. Thanks for this you just saved me half an hour of pointless debugging.
    ReplyDelete
  19. Thanks for putting it up, I also forgot to make the class PUBLIC xD
    ReplyDelete
  20. thanks, this helped alot
    ReplyDelete
  21. 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.
    ReplyDelete
  22. thanks, worked for me :)
    ReplyDelete