Flex的元素includein [英] Flex element includein

查看:148
本文介绍了Flex的元素includein的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Flex中,我们可以通过这个分配状态的元素:

In Flex, we can assign state to an element via this:

<s:Button id="mybtn" includeIn="mystate" label="button label"/>

我们如何才能做到 includeIn 使用ActionScript?

How can we do the includeIn with ActionScript?

感谢您。

推荐答案

includeIn 伪属性只存在于MXML语言。我把它称为伪属性,因为它不映射到属性或(Button类的在你的榜样)的样式。

The includeIn pseudo-attribute only exists in the MXML language. I call it a pseudo-attribute because it does not map to a property or a style (of the Button class in your example).

相反,它是旧的MX 为addItems 标签的速记符号。在该语法您的例子看起来是这样的:

Instead it is a shorthand notation of the old mx AddItems tag. In that syntax your example would look something like this:

<mx:states>
    <mx:State name="normal"/>
    <mx:State name="mystate">
        <mx:AddItems items="{mybtn}"/>
    </mx:State>
</mx:states>

<mx:Button id="mybtn"/>

我提到这一点,因为这是 includeIn 产生的动作code是非常相似的。这是什么样子:

I mention this, because the ActionScript code that is generated for includeIn is very similar. This is what it looks like:

states = [
    new State ({
        name: "normal",
        overrides: []
    }),
    new State ({
        name: "mystate",
        overrides: [
          new AddItems().initializeFromObject({
            itemsFactory: _TestFlex_Button1_factory,
            destination: null,
            position: "first"
          })
        ]
    })
];

所不同的是,它使用一个工厂来实例化按钮。
请注意,如果你有兴趣在从MXML code产生的动作code,你可以看看它只是通过传递继续生成,动作标志的编译器(见 mxmlc编译选项

The difference is that it uses a factory to instantiate the Button.
Note that if you're interested in the ActionScript code that is generated from MXML code, you can have a look at it simply by passing the keep-generated-actionscript flag to the compiler (see mxmlc compiler options).

当然,如果你真的想'手动'写逻辑(我不会),它可能更容易覆盖的 setCurrentState()或侦听的 CURRENT_STATE_CHANGE 事件,并调用的addElement() removeElement()取决于值 currentState的

Of course if you really want to 'manually' write that logic (I wouldn't), it may be easier to override setCurrentState() or listen for the CURRENT_STATE_CHANGE event, and call addElement() or removeElement() depending on the value of currentState.

这篇关于Flex的元素includein的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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