1

I'm making a little application in Actionscript 3. In my initApp.as I have created another class which needs to edit the currentState, which is only accessible from the main .as (initApp.as). I found a solution such that I can reach the currentState property from my other class: Application.application.currentState.

This is however not a good solution as it couples the classes too much.. is there a better way of editing the currentState from other classes?

Linora
  • 10,418
  • 9
  • 38
  • 49

1 Answers1

2

I would suggest you use events and a central dispatcher. For example:

In InitApp.as

Dispatcher.instance.addEventListener(StateChangeEvent.STATE_CHANGE, onStateChange);

protected function onStateChange(e:StateChangeEvent):void
{
    this.currentState = e.newState;
    // perhaps dispatch another state change event that all views can listen for?
}

In your other class

Dispatcher.instance.dispatchEvent(new StateChangeEvent(StateChangeEvent.STATE_CHANGE, newState);

where Dispatcher is a singleton and StateChangeEvent is a custom event with a newState property. Good luck!

heavilyinvolved
  • 1,575
  • 1
  • 11
  • 12