# Need some help with class variables

**URL:** <https://forum.kirupa.com/t/need-some-help-with-class-variables/230161>\
**Category:** Uncategorized\
**Created:** [June 23, 2007, 8:54am UTC](https://forum.kirupa.com/t/need-some-help-with-class-variables/230161 "2007-06-23T08:54:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chesso](https://avatars.discourse-cdn.com/v4/letter/c/f14d63/32.png) [@Chesso](https://forum.kirupa.com/u/Chesso)\
**Post date:** [June 23, 2007, 8:54am UTC](https://forum.kirupa.com/t/need-some-help-with-class-variables/230161/1 "2007-06-23T08:54:36Z")

</div>

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

I have a class called Main, that extends MovieClip (it is dynamic) to house _my global_ variables, functions etc.

This Main class, has a particular instance variable called tower\_ind, I have created an instance of this class called main.

And using this right after: main.tower\_ind = 5; trace(main.tower\_ind); , appears to work perfectly.

But if I try to access this variable from another class which I create an instance of afterwards, I get the error mentioned at the top of this post.

I access it like this in the class:

```auto

var inst:String = "tower_basic1_" + this.root.main.tower_ind;

```

I have tried root, stage, parent, this.root, this.parent, this.stage etc etc, but no matter what, it still complains…

Although in the future I may be converting to using a public static variable of my tower class to keep hold of the index (should piss this problem right off I hope), but I will still need to get this kind of result working for other things.
