for my current project I am starting to work with AS3 and I have written a ClipManager class where I can define an MC like “mainView” during initialization like this:
clipManager:ClipManager = new ClipManager(mainView);
With my clipManager I can now easily load stuff into the mainView etc. The problem is that I want every button throughout the whole thing to access Class Methods of this instance to alter the mainView. Can I have something like a global Class instance in Flash or is there any smarter way to achieve what I am trying to do?
You can either add your ClipManager class as a static somewhere – i.e. a god object – (perhaps your main class) and access it through that, or you can use the Singleton pattern.
A common way to implement it in as3:
Now, to access your class, you call
Singleton.instance. There’ll only ever be one instance of this class.As for anti-patterns etc, well that’s another post 🙂