Skip to main content
Inspiring
September 16, 2011
Question

Why does this code work in one place but not another?

  • September 16, 2011
  • 1 reply
  • 910 views

I have a class. Inside the class are two public functions. One calls this:

MovieClip(root)["bmc"+PuzzleGlobals.puzzleAbbrev].addChild(this);

And the other calls this:

MovieClip(root)["bmc"+PuzzleGlobals.puzzleAbbrev].addChild(fwgame); 

fwgame is declared like this (before the addChild):

var fwgame:FireworkGame = new FireworkGame(); 

trace (fwgame); //traces correct object

trace (MovieClip(root)["bmc"+PuzzleGlobals.puzzleAbbrev]); //returns a 1009 error

The first line of code works. The second line returns a 1009 error,  "Cannot access a property or method of a null object reference."

Why would it be doing that?

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
September 16, 2011

there are a number of possible causes.  use the trace() function to debug:

start debugging by using the following in both functions:

trace(this);  // to check if you're still within scope of your class in both.

AmbariAuthor
Inspiring
September 16, 2011

I'm sorry, I'm super confused.

I tried it but trace (this) just traces the object that I've picked up. Wouldn't MovieClip(root) automatically send it back to the root? I'm sorry I'm not sure what I'm looking for.