Flex 3:状态:CreationPolicy = 全部

发布于 2024-08-10 14:33:10 字数 163 浏览 3 评论 0原文

我有一个具有不同状态的组件,当我在另一个状态中分配一些值时,我收到运行时错误 [null]

如何一次加载所有状态?使用创建策略或其他方式?

在TabNavigator中,creationpolicy=all解决了这个问题,但是当状态很多时如何解决这个问题呢?

谢谢

i have a component with different states, when i assign some value in another state, i get a runtime error [null]

How can i load all the states at once? using creationpolicy or anyther way?

In TabNavigator, creationpolicy=all solves that problem, but how to solve this issue when there are many states?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

所有深爱都是秘密 2024-08-17 14:33:11

AddChild 元素有一个creationPolicy 属性,默认为“auto”,但也接受“all”或“none”。将其设置为“全部”应该适合您:

http ://livedocs.adobe.com/flex/3/langref/mx/states/AddChild.html#creationPolicy

The AddChild element has a creationPolicy property, which defaults to 'auto' but accepts 'all' or 'none' as well. Setting it to 'all' should work for you:

http://livedocs.adobe.com/flex/3/langref/mx/states/AddChild.html#creationPolicy

红颜悴 2024-08-17 14:33:11

这不适用于 Flex 4.6,因为您收到弃用错误消息。似乎 mxml 编译器不会识别任何形式的尝试强制加载所有状态的组件的行为。解决此问题的一种方法是在创建时手动将状态切换到您正在使用的所有状态,例如: currentState = "Edit";当前状态 = "记录";当前状态=“默认”;请注意,您甚至不能使用带有字符串常量的 for every in 循环,您必须使用内联字符串文字,以便 mxml 编译器接受它们。

另一个看起来更简洁的解决方案是按如下方式初始化组件:

ref: http://compacted.wordpress.com/2009/08/14/unit-testing-flex-states/#comments

public static function initializeStates(component:UIComponent):void {
  for each (var state:mx.states.State in component.states) {
    for each (var override:IOverride in state.overrides) {
      override.initialize();
    }
  }
}

This does not work for flex 4.6 since you receive deprecation error message. Seems that the mxml compiler will not recognise any form of trying to force components in all states to be loaded. One workaround to this, is to at creation time manually switch states to all those you are using such as: currentState = "Edit"; currentState = "Record"; currentState = "Default"; note that you can't even use a for each in loop with string constants, you have to use in-line string literals so that the mxml compiler will accept them.

Another solution which seems much neater is to initialize your component as follows:

ref: http://compacted.wordpress.com/2009/08/14/unit-testing-flex-states/#comments

public static function initializeStates(component:UIComponent):void {
  for each (var state:mx.states.State in component.states) {
    for each (var override:IOverride in state.overrides) {
      override.initialize();
    }
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文