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

**URL:** <https://forum.kirupa.com/t/why-does-this-code-work-in-one-place-but-not-another/324941>\
**Category:** flash\
**Created:** [September 16, 2011, 8:35pm UTC](https://forum.kirupa.com/t/why-does-this-code-work-in-one-place-but-not-another/324941 "2011-09-16T20:35:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sogj](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/sogj/32/3189_2.png) [@sogj](https://forum.kirupa.com/u/sogj)\
**Post date:** [September 16, 2011, 8:35pm UTC](https://forum.kirupa.com/t/why-does-this-code-work-in-one-place-but-not-another/324941/1 "2011-09-16T20:35:13Z")

</div>

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

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

```

And the other calls this:

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

```

fwgame is declared like this (before the addChild):

```php
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?
