如何访问一个变量,或从一个MXML改变(如TabNavigator容器)元素的状态到另一个MXML? [英] How can i access a variable or change the state of an element(like tabNavigator) from one mxml to another mxml?

查看:160
本文介绍了如何访问一个变量,或从一个MXML改变(如TabNavigator容器)元素的状态到另一个MXML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何可以访问一个变量,或从一个MXML改变(如TabNavigator容器)元素的状态到另一个MXML在FLEX 4.6 ??

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不是在一个父子关系; (相同的组件作为一个例子的AKA两个孩子)他们它们不应彼此直接通信。他们应该派遣事件,相互父母应该处理,使用设置值或执行它自己孩子的方法。

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.

这篇关于如何访问一个变量,或从一个MXML改变(如TabNavigator容器)元素的状态到另一个MXML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆