# Proper use of static variables in AS 2.0

**URL:** <https://forum.kirupa.com/t/proper-use-of-static-variables-in-as-2-0/131783>\
**Category:** Uncategorized\
**Created:** [December 19, 2004, 8:09pm UTC](https://forum.kirupa.com/t/proper-use-of-static-variables-in-as-2-0/131783 "2004-12-19T20:09:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![son\_of\_light](https://avatars.discourse-cdn.com/v4/letter/s/df705f/32.png) [@son\_of\_light](https://forum.kirupa.com/u/son_of_light)\
**Post date:** [December 19, 2004, 8:09pm UTC](https://forum.kirupa.com/t/proper-use-of-static-variables-in-as-2-0/131783/1 "2004-12-19T20:09:50Z")

</div>

Hello all, im about 3-4 months into the whole OOP style of programming and everything is really starting to come together. I have a ? regarding static class variables and how to use them properly.

My situation is, I have created a class to define my main navigation buttons. I would like to handle which button is clicked/pressed as simply and elegantly as possible, and I figured the best way would be to add a static variable to the class that keeps track of the current button pressed.

Here’s some quick pseudo-code.

```auto

class MainButton ext MC
 
static var currentButton:MainButton
public var sectionToLoad:String
 
public static function getCurrentButton()
public function getSection()
 
button.onPress = 
		currentButton = this
		// other button actions.
 
 
// then i can check for what the currently clicked button
// is and now access its variables.
 
MainButton.getCurrentButton().getSection()
etc.
etc.
etc.
 

```

I am curious if this is a “proper” way to go about tracking the buttons. I find it is pretty elegant, but i’d rather make sure that this is a good practice of using static class variables.

Also, it looks to me that all custom class definitions become a \_global object?  
Therefore I could access MainButton.getCurrentButton()… from anywhere in my App. Is this correct?

Thanks! 🙂
