Flex 4 状态——“正确”句法
好的,有人可以告诉我在 Flex 4 中的 mxml 中执行状态的 REAL 语法吗???
我已经看到了以下两种方法(并实现了两种方法),但不知道哪种方法是“正确的”或首选的。
在组件中的
<fx:Declarations>
...
<s:State name="state1" />
<s:State name="state2" />
<s:State name="state3" />
</fx:Declarations>
<s:Button id="button1" ... />
...
<more components>
或
“最顶层”级别中
<s:states>
<s:State name="state1" />
<s:State name="state2" />
<s:State name="state3" />
</s:states>
<s:Button id="button1" ... />
...
<more components>
OK, can someone please tell me the REAL syntax for doing states in mxml in Flex 4???
I've seen both of the following (and implemented both) and don't know which way is "right" or preferred.
In the <fx:Declarations>
<fx:Declarations>
...
<s:State name="state1" />
<s:State name="state2" />
<s:State name="state3" />
</fx:Declarations>
<s:Button id="button1" ... />
...
<more components>
OR
"Top-most" level in a component
<s:states>
<s:State name="state1" />
<s:State name="state2" />
<s:State name="state3" />
</s:states>
<s:Button id="button1" ... />
...
<more components>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能是第二个;但这取决于你想做什么。
此语法:
在类 State 的组件内创建三个变量。这与在 ActionScript 中执行类似操作相同:
在组件上创建状态时,您可能想要做的不仅仅是创建状态。您想要将该状态指定为当前组件的状态。
这就是第二个语法的实际作用:
这将创建三个状态变量作为数组,并将它们分配给顶级组件的状态属性。从概念上讲,就像 ActionScript 中的这样:
编译器完全有可能对第一个语法进行一些魔法来创建这些状态实例并将它们分配给 states 数组,但我不确定。我以前从未见过有人使用该语法。我希望这两种方法都能编译。我只希望第二种方法能够在可以切换的组件上实际创建状态。
Probably the second one; but It depends what you're trying to do.
This Syntax:
Creates three variables inside the component of the class State. It would be the same as doing something like this in ActionScript:
When creating states on a component, you probably want to do more than just create a state. You want to assign the state as a state of the current component.
That is what your second syntax actually does:
This creates three state variables as an array, and assigns them to the state property of the top level component. Conceptually like this in ActionScript:
It is entirely possible that the compiler does some magic on the first syntax to create those state instance and assign them to the states array, but I'm not sure. I've never seen anyone use that syntax before. I would expect both approach to compile. I would only expect the second approach to actually create states on a component that you can switch between.