Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

TypeError: Error #1009: Cannot access a property or method of a null object reference.

Explorer ,
Feb 21, 2015 Feb 21, 2015

Okay, so my game codes are not problematic at all and don't effect the game UNLESS I declare the level "OneManager" as a variable.

OneManager is the class for my level. The level is a movieclip containing all the level's components. And Main is the document class.

ac.png

TypeError: Error #1009: Cannot access a property or method of a null object reference.

at OneManager()

at Main()

This is the code for my OneManager class.

ac2.png

And, this is the code for my Main document class.

ac3.png

Okay, so when I try to declare the movieClip "OneManager" as a variable from the main document, so I can add it to the stage after the play button is clicked. It shows random errors from the output and says the codes from the other classes are null. I don't really know why declaring and instiantating it as a variable from the main document gives errors to other classes.

NONE of my classes had errors before I tried to declare and instiantating it. I tried adding the level one movieclip with the OneManager class manually to the stage. Without making it a variable from the main document. And then the game worked fine and none of the classes had errors.

I'm wondering why does it give random errors by trying to put it as a variable in the main document? Other variables work fine, just as the mountains and homePage variables. I'm pretty sure that none of these codes are null as I tried it manually without the main class and it worked fine with no errors.

Please help, thanks!

TOPICS
ActionScript
498
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Feb 21, 2015 Feb 21, 2015

If you make use of the trace function you can determine where the failure erupts by trying to trace the objects being targeted in the lines that are indicated in the error message.

The 1009 error indicates that one of the objects being targeted by your code is out of scope.  This could mean that the object....

 

- is declared but not instantiated

- doesn't have an instance name (or the instance name is mispelled)

- does not exist in the frame where that code is trying to talk to it

- is animated into

...
Translate
LEGEND ,
Feb 21, 2015 Feb 21, 2015

The error appears to be indicating the problem lies in line 38 of the OneManager class file.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 21, 2015 Feb 21, 2015

I don't think it makes any sense. I deleted line 38, then the problem indicated until line 39, then I deleted them over and over. Then practically until my code was useless, that's when I FINALLY got no error...

Like I said, these codes don't even look problematic at all. I even tried adding them manually by adding the class's movieclip to the stage myself and it worked completely fine. But what I'm trying to do is add it to the stage through code by making this class's movieclip a variable and when the button is clicked, but if I did that - I would get these random errors from other classes.

I'm not sure what's wrong here. There is no trouble compiling, so I get no compile errors. Only errors from the output. These lines of codes aren't null, but the output says it is. I'm confused.

Help! Thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 21, 2015 Feb 21, 2015

If you make use of the trace function you can determine where the failure erupts by trying to trace the objects being targeted in the lines that are indicated in the error message.

The 1009 error indicates that one of the objects being targeted by your code is out of scope.  This could mean that the object....

 

- is declared but not instantiated

- doesn't have an instance name (or the instance name is mispelled)

- does not exist in the frame where that code is trying to talk to it

- is animated into place but is not assigned instance names in every keyframe for it

- is one of two or more consecutive keyframes of the same objects with no name assigned in the preceding frame(s).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 22, 2015 Feb 22, 2015
LATEST

Oh, it seems like it's because the movieclip isn't even added to the stage before the button is clicked. So that's why it's null... And it works if I add it to the stage manually. I see now.

A silly and obscure mistake.

Thanks anyways.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines