Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache flex “访问”;“当前状态”;其他班级的?_Apache Flex_Actionscript 3 - Fatal编程技术网

Apache flex “访问”;“当前状态”;其他班级的?

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

我正在ActionScript3中制作一个小应用程序。在我的initApp.as中,我创建了另一个需要编辑currentState的类,该类只能从main.as(initApp.as)访问。我找到了一个解决方案,可以从另一个类Application.Application.currentState访问currentState属性


然而,这并不是一个好的解决方案,因为它太多地耦合了类。。有没有更好的方法从其他类编辑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属性的自定义事件。祝你好运