在 Flex 中的组件初始化期间设置变量
我正在加载一个组件,该组件进行 HTTPService 调用以获取数据,然后使用这些数据设置组件中的某些变量。我在 init() 函数中进行 HTTPService 调用(用于初始化事件),然后根据 HTTPService 结果处理程序中收到的数据设置变量。然而,在初始化阶段和创建完成阶段,变量仍然为空。如果我尝试读取creationComp()函数中的变量(对于creationComplete事件),这些变量仍然为空。这是正确的吗?
我想我不太了解 Flex 初始化周期。这些变量何时实际设置并可供使用?我需要在组件加载后自动操作这些变量。在creationComplete之后是否有一个合适的事件或其他方法来解决这个问题?我正在使用 Flex 3。
I am loading a component which makes a HTTPService call to get data that will then be used to set certain variables in the component. I make the HTTPService call in an init() function (for the initialization event) and then set the variables according to the data received in the HTTPService result handler. However, the variables are still null at both the initialize stage and at the creationComplete stage. If I try and read the variables in a creationComp() function (for the creationComplete event), those variables are still null. Is this correct?
I guess I don't understand the flex initialization cycle very well. When are those variables actually set and available to be used? I need to manipulate those variables automatically after the component loads. Is there an event that comes after creationComplete that is appropriate or some other way to approach this? I am using Flex 3.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您对 Flex 组件生命周期的理解是正确的;在创建完成之前初始化事件触发。
然而,HTTPService 调用是一个单独的异步操作。不保证在creationComplete 事件触发时调用结果处理程序。您应该在结果处理程序中对变量进行操作。
Your understanding of the Flex component lifecycle is correct; initialize event fires before creationComplete.
However, an HTTPService call is a separate asynchronous operation. The result handler is not guaranteed to be called by the time the creationComplete event fires. You should do the manipulation of the variables in the result handler instead.
您应该考虑在 HTTPService 返回之前阻止从组件分派creationComplete 事件,然后自己手动分派该事件。
这会解决你的时间问题。
You should think about preventing the creationComplete event being dispatched from your component until the HTTPService has returned, then manually dispatch the event yourself.
That would sort out your timing issues.