I know global variables are supposed to be bad but is it possible to create global classes? I am creating an application and I want to have one class that handles sound. From any class I would like to be able to say soundhandler.playSound(); without having to pass references all over the place. It should just know it is there.
Any help greatly appreciated.
You’re referring to
staticmembers.Your class
SoundHandlerwould have a static method calledplaySound(), which can be implemented like so:Your
playSound()method is now accessible via:Note: You mentioned global methods being bad, however this is a perfect candidate for these and something I would actually recommend (as much as I hate using static).
Additional: ActionScript 3’s
Mathclass contains mostly static members e.g.Math.round()No, in fact you shouldn’t make an instance of SoundHandler at all. The only requirement is that you must have
SoundHandlerimported in your current class to access it: