For an AS3 project I’m working on I needed to know whether or not a UIComponent had passed a certain state (for example childrenCreated or initialize). Rather than overriding the corresponding protected methods I wrote a (really) simple class called StateManager that lets you make inquiries about any UIComponent that has been registered with the class.

Because StateManager is kind of an abstract class (not in the OOP sense) I decided not to create a demo. You can however check out the source and documentation here:

StateManager is a singleton class and when creating a custom component class you might use it somewhat like this:

package {

  import mx.core.UIComponent;
  import com.rubenswieringa.managers.StateManager;

  class SomeComponent extends UIComponent {

    // register the class, typically in the class constructor:
    public function SomeComponent ():void {

    // somewhere later in the code:
    public function someFunction ():void {
      // only execute if this class has already passed the creationComplete event:
      if (StateManager.instance.getState(this) >= StateManager.CREATION_COMPLETE){
        // do something..

One thought on “StateManager

Comments are closed.