问题描述
如何在 FLEX 4.6 中访问变量或将元素(如 tabNavigator)的状态从一个 mxml 更改为另一个 mxml??
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??
推荐答案
每个单独的 MXML 文件都应该被视为一个类,因为它们就是这样.
Each separate MXML file should be viewed as a class, since that is what they are.
在封装理论中;两个类不应直接访问/更改彼此的变量或状态.他们应该使用 MXML 类的开发者提供的 API.
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.
如果 MXML 1 是 MXML 2 的父级;然后 MXML1 可以通过设置公共属性或调用公共方法将数据传递给 MXML2.
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 可以通过调度事件将数据传递给 MXML1.
MXML2 can pass data to MXML1 by dispatching events.
如果 MXML1 和 MXML2 不是父子关系;(又名同一组件的两个子组件作为一个示例)他们不应该直接相互通信.他们应该调度事件,共同的父级应该处理并使用这些事件在自己的子级上设置值或执行方法.
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.
从封装的角度来看,这应该是使用 ActionScript/Flex 的内置工具来完成的.
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.
这篇关于如何访问变量或将元素(如 tabNavigator)的状态从一个 mxml 更改为另一个 mxml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!