Skip to main content
Participating Frequently
November 4, 2008
Answered

Has anyone found a solution to Error 1009?

  • November 4, 2008
  • 3 replies
  • 647 views
TypeError: Error #1009: Cannot access a property or method of a null object reference

Ok. I'll simplify my code so that the problem can be better understood.

I have a main.as class at the document root. Here I have a property bb:bigBox = new bigBox() and added it to the root. I also have sb:smallBox = new smallBox() which is then added to bb. However small box has to store bigBox's initial x,y value state. So these properties must be stored through the smallBox constructor. This is where I get the Error: 1009.

Any and all help is appreciated. Thanks in advance

edit: I've tried moving around code, placing init() methods in the timeline, nothing seems to work. why is something so simple giving so much trouble. Can Macromedia/Adobe ever get this thing right? Finally after years of Flash programming, the language is starting to look sensible, now I'm stuck on this kink. I have looked this problem up all over the web and no one seems to have a valid solution. What's up Adobe?
This topic has been closed for replies.
Correct answer clbeech
change the order of operations here, placing: sb = new smallBox(); following the line: bb = new bigBox();

you cannot add a child to bb that does not yet exist. then assign the x/y position within the main class previous to adding it to the display list, rather than in the smallBox constructor, as in:

3 replies

Participating Frequently
November 4, 2008
Although the answer requires that I make several members and methods public this is the best solution. Thanks Bleech.
clbeech
Inspiring
November 4, 2008
cool you're welcome - ok another way to go about this if you wish to just store the value rather than assign it, would be to pass it in the smallBox constructor. I also usual as a common practice pass a reference to the Doc class within it as well, something like:
Participating Frequently
November 4, 2008
Thanks, beech. actaully that's the way it was before. I only changed it as I was rewriting the simplified code. But realized it didn't work.

Also, I am only trying to store the value of bigBox not assign it to smallBox.

Thanks again

p.s. I've also edited the original post
clbeech
clbeechCorrect answer
Inspiring
November 4, 2008
change the order of operations here, placing: sb = new smallBox(); following the line: bb = new bigBox();

you cannot add a child to bb that does not yet exist. then assign the x/y position within the main class previous to adding it to the display list, rather than in the smallBox constructor, as in: