Flex 3:状态:CreationPolicy = 全部
我有一个具有不同状态的组件,当我在另一个状态中分配一些值时,我收到运行时错误 [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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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
这不适用于 Flex 4.6,因为您收到弃用错误消息。似乎 mxml 编译器不会识别任何形式的尝试强制加载所有状态的组件的行为。解决此问题的一种方法是在创建时手动将状态切换到您正在使用的所有状态,例如: currentState = "Edit";当前状态 = "记录";当前状态=“默认”;请注意,您甚至不能使用带有字符串常量的 for every in 循环,您必须使用内联字符串文字,以便 mxml 编译器接受它们。
另一个看起来更简洁的解决方案是按如下方式初始化组件:
ref: http://compacted.wordpress.com/2009/08/14/unit-testing-flex-states/#comments
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