Flex 4 状态——“正确”句法

发布于 2024-12-07 05:46:34 字数 690 浏览 3 评论 0原文

好的,有人可以告诉我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

脱离于你 2024-12-14 05:46:34

可能是第二个;但这取决于你想做什么。

此语法:

<fx:Declarations>
  ...
  <s:State name="state1" />
  <s:State name="state2" />
  <s:State name="state3" />
</fx:Declarations>

在类 State 的组件内创建三个变量。这与在 ActionScript 中执行类似操作相同:

var myState1 : State = new State();
var myState1 : State = new State();
var myState1 : State = new State();

在组件上创建状态时,您可能想要做的不仅仅是创建状态。您想要将该状态指定为当前组件的状态。

这就是第二个语法的实际作用:

<s:states>
  <s:State name="state1" />
  <s:State name="state2" />
  <s:State name="state3" />
</s:states>

这将创建三个状态变量作为数组,并将它们分配给顶级组件的状态属性。从概念上讲,就像 ActionScript 中的这样:

var myState1 : State = new State();
var myState1 : State = new State();
var myState1 : State = new State();
this.states = new Array();
this.states.push(myState1);
this.states.push(myState2);
this.states.push(myState3);

编译器完全有可能对第一个语法进行一些魔法来创建这些状态实例并将它们分配给 states 数组,但我不确定。我以前从未见过有人使用该语法。我希望这两种方法都能编译。我只希望第二种方法能够在可以切换的组件上实际创建状态。

Probably the second one; but It depends what you're trying to do.

This Syntax:

<fx:Declarations>
  ...
  <s:State name="state1" />
  <s:State name="state2" />
  <s:State name="state3" />
</fx:Declarations>

Creates three variables inside the component of the class State. It would be the same as doing something like this in ActionScript:

var myState1 : State = new State();
var myState1 : State = new State();
var myState1 : State = new State();

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:

<s:states>
  <s:State name="state1" />
  <s:State name="state2" />
  <s:State name="state3" />
</s:states>

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:

var myState1 : State = new State();
var myState1 : State = new State();
var myState1 : State = new State();
this.states = new Array();
this.states.push(myState1);
this.states.push(myState2);
this.states.push(myState3);

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文