我有一个组件,一旦准备就绪,我需要根据我从XML读入的变量设置状态。 我尝试使用creationComplete ,但它显然没有准备好,因为状态没有设置元素正确渲染,但状态和渲染工作正常,如果我通过对某个元素的单击操作进行后续状态更改。
在这种情况下我应该怎么做才能确保在正确的时间设置状态,并且由于includeIn而应该出现的元素存在以便可以呈现它们? initialize而不是creationComplete似乎不是第一次创建组件时的技巧。 对组件的任何连续调用都可以。
I have a component that, once it's all ready, I need to set the state based on a variable I'm reading in from XML. I tried doing it with creationComplete, but it's apparently not ready, as the state isn't being set with elements rendering properly, but the states & rendering work fine if I do a subsequent state change with a click action on some element.
What should I do in this situation to make sure the state gets set at the right time & elements that should appear due to includeIn exist so they can be rendered? initialize instead of creationComplete doesn't seem to do the trick for the first time the component is created. Any successive calls to the component are fine.
最满意答案
仅供参考, initialize不起作用并不奇怪,它在创建子元素之前被触发,然后激活creationComplete 。 由于creationComplete是要触发的init生命周期中的最后一个事件。
有时,如果组件的creationComplete事件过早触发,则需要从父容器更改子组件状态。
任何组件的creationComplete在其所有子组件触发了creationComplete触发。
查看Adobe 有关组件实例化生命周期的文档
creationPolicy的
您可能还需要为all应用程序设置creationPolicy属性。 (我认为默认是auto )
enterState
您可以在状态声明中挂钩事件处理程序,一旦运行状态中的对象应该可用。
visible.state属性。
最终,您可以将基于状态的对象的容器设置为不可见/不包含在布局中(visible和includeInLayout属性)。在场合,您将没有任何其他方法通过代码到达对象,因为它不存在。 但是, enterState应仅在输入视图状态时执行,因此该状态内的对象应完全可用。
FYI, it's no surprise that initialize didn't work, it's fired before the child elements are created, and creationComplete then fires. Since creationComplete is the last event in the init lifecycle to fire.
Sometimes you need to change child component state from the parent container, if the creationComplete event for the component is fired prematurely.
creationComplete for any component fires after all of it's child components have fired their creationComplete.
Have a look at Adobe's documentation for the component instantiation life cycle
creationPolicy
You may also need to set the creationPolicy attribute for your app, to all. (I think it's default is auto)
enterState
You can hook an event handler on enterState in a state declaration, once that runs the objects within the state should be available.
visible.state properties.
Ultimately you can set the containers for your state based objects to be invisible / not included in the layout (visible and includeInLayout properties.) On occassion you won't have any other method of reaching an object through code, because it won't exist. However, enterState should only execute when a view state has been entered, so objects within that state should be fully available.
更多推荐
发布评论