Copy link to clipboard
Copied
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.
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.
And, this is the code for my Main document class.
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!
1 Correct answer
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
...Copy link to clipboard
Copied
The error appears to be indicating the problem lies in line 38 of the OneManager class file.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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).
Copy link to clipboard
Copied
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.

