# Declaring a global variable?

**URL:** <https://forum.kirupa.com/t/declaring-a-global-variable/324278>\
**Category:** flash\
**Created:** [August 11, 2011, 9:00pm UTC](https://forum.kirupa.com/t/declaring-a-global-variable/324278 "2011-08-11T21:00:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lazerbrains](https://avatars.discourse-cdn.com/v4/letter/l/b19c9b/32.png) [@lazerbrains](https://forum.kirupa.com/u/lazerbrains)\
**Post date:** [August 11, 2011, 9:00pm UTC](https://forum.kirupa.com/t/declaring-a-global-variable/324278/1 "2011-08-11T21:00:17Z")

</div>

I am trying to declare a global variable, a variable that will be recognized throughout the entire site. Then I am checking for that variable with a function inside of a movieClip, that is inside of another movieClip.

I declare the variable on the main timeline like this:

```auto
var habitat:String = "habitat"

```

Then set the variable depending on which page you go to: (you must go to one before moving on)

```auto
habitat = "forest";

```

And then on nested two movieClips down, I check for it using this function:

```auto
function habitatBG(event:Event):void {

	if (habitat == "forest") {
		MovieClip(parent.parent).gotoAndStop("forest_critters");
		trace ("Forest VAR 1");
	} else if (habitat == "seashore"){
		MovieClip(parent.parent).gotoAndStop("seashore_critters");
		trace ("Seashore VAR 1");
    } else if (habitat == "prairie"){
		MovieClip(parent.parent).gotoAndStop("prairie_critters");
		trace ("Prairie VAR 1");
    } else if (habitat == "desert"){
		MovieClip(parent.parent).gotoAndStop("desert_critters");
		trace ("Desert Var 1");
    } else if (habitat == "marine"){
		MovieClip(parent.parent).gotoAndStop("marine_critters");
		trace ("Marine VAR 1");
    } else {
		MovieClip(parent.parent).gotoAndStop("home");
		trace ("Wlcome back home");
    }
}

```

However when I publish, it tells me:

```auto
Symbol 'journal_open', Layer 'Actions', Frame 1, Line 27	1120: Access of undefined property habitat.

```

What am I doing wrong?
