没怎么用过State, 据说Flex4中State有很大更新, 今天小用了下. 发现一个问题:

非Start State中的Component在Application Create complete后不能立即使用. 于是想到了之前常用的creationPolicy – 统统设置为ALL, 结果仍旧无济于事.

解决方法: 设定组件itemCreationPolicy="immediate".

API:

Use the itemCreationPolicy property to specify the creation policy. The itemCreationPolicy property supports the following values:

deferred (默认值 – State活动时再创建)
Creates the component instance when it is first added by a change to the view state. This is the default value.

immediate (立即创建)
Creates the component instance at application startup.

See: http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf63611-7ffa.html
注意:

itemCreationPolicy and itemDestructionPolicy attributes must accompany either the includeIn or excludeFrom attribute.   
组件必须已经使用includeIn /excludeFrom 属性, 因此如果组件未设定显示的State(可能是外部容器设定了), 又要在该组件上单独使用itemCreationPolicy, 那就需要在该组件上先通过includeIn /excludeFrom 设定下要显示/排除的State.

另: 与创建政策Create Policy对应的, 还有销毁政策: itemDestructionPolicy
关于Flex4 State中文介绍可参见: http://swfever.com/?p=717

@import url(http://www.blogjava.net/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);