How can i access a variable or change the state of an element(like tabNavigator) from one mxml to another mxml?

落花浮王杯 提交于 2020-01-17 04:33:06

问题


How can i access a variable or change the state of an element(like tabNavigator) from one mxml to another mxml in FLEX 4.6??


回答1:


Each separate MXML file should be viewed as a class, since that is what they are.

In the theory of encapsulation; two classes should not directly access / change each others variables or state. They should use an API provided by the developer of the MXML Class.

If MXML 1 is the parent of MXML 2; then MXML1 can pass data to MXML2 by setting public properties or calling public methods.

MXML2 can pass data to MXML1 by dispatching events.

If MXML1 and MXML2 are not in a parent child relationship; (AKA Both children of the same component as one example) they they should not communicate with each other directly. They should dispatch events which the mutual parent should handle and use to set values or execute methods on it's own children.

From an encapsulation standpoint, that is how it should be done using the built in facilities of ActionScript / Flex.

What a lot of people do as part of building applications is to make use of dependency injection. That was values that are "global to the application" can be shared among multiple components. Another approach to doing this is to use a Singleton. A third approach might be to make use of static values on a class; which can be accessed without accessing an instance of a class.



来源:https://stackoverflow.com/questions/10948564/how-can-i-access-a-variable-or-change-the-state-of-an-elementlike-tabnavigator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!