Proper use of static variables in AS 2.0

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.


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! :slight_smile: