Apache flex “访问”;“当前状态”;其他班级的?
我正在ActionScript3中制作一个小应用程序。在我的initApp.as中,我创建了另一个需要编辑currentState的类,该类只能从main.as(initApp.as)访问。我找到了一个解决方案,可以从另一个类Application.Application.currentState访问currentState属性Apache flex “访问”;“当前状态”;其他班级的?,apache-flex,actionscript-3,Apache Flex,Actionscript 3,我正在ActionScript3中制作一个小应用程序。在我的initApp.as中,我创建了另一个需要编辑currentState的类,该类只能从main.as(initApp.as)访问。我找到了一个解决方案,可以从另一个类Application.Application.currentState访问currentState属性 然而,这并不是一个好的解决方案,因为它太多地耦合了类。。有没有更好的方法从其他类编辑currentState?我建议您使用事件和中央调度器。例如: 在InitApp.a
然而,这并不是一个好的解决方案,因为它太多地耦合了类。。有没有更好的方法从其他类编辑currentState?我建议您使用事件和中央调度器。例如: 在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?
}
在你的另一节课上
Dispatcher.instance.dispatchEvent(new StateChangeEvent(StateChangeEvent.STATE_CHANGE, newState);
其中,Dispatcher是单例,StateChangeEvent是具有newState属性的自定义事件。祝你好运