有没有办法强制“updatedisplaylist”?立即而不是稍后某个时刻
在 Flex 组件生命周期中,当我们对组件属性进行一些更改后,失效方法会安排稍后调用 commitProperties
、updateDisplayList
等方法。我需要立即调用 updateDisplayList
。有没有一些直接的方法可以做到这一点。 目前,两个标签在循环完成后同时更改。相反,我需要它像这样工作,首先渲染更新的“myButton1”标签,然后进入循环,然后更新 myButton2 的标签。我知道,这是弹性赛道问题,但没有什么方法可以实现这一点吗?
myButton1.label = 'New Label1' ;
// Some logic to forcibly make the screen reflect it
for (var i:int = 0; i < 500 ; i ++){
//a dummy loop
}
myButton2.label = 'New Label2' ;
In flex component life cycle, after we make some change in a components property, invalidation methods schedules a call to methods like commitProperties
, updateDisplayList
, etc for some later time. I need to call the updateDisplayList
instantaneously. Is there some direct way to do this.
Currently, both the labels are changed simultaneously after completion of the loop. Instead I need it to work like this, to first render the updated 'myButton1' label then enter the loop and then update myButton2's label. I know, it is elastic race track issue, but isn't there some way to achieve this ?
myButton1.label = 'New Label1' ;
// Some logic to forcibly make the screen reflect it
for (var i:int = 0; i < 500 ; i ++){
//a dummy loop
}
myButton2.label = 'New Label2' ;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用 myButton1.validateNow() ,但不鼓励使用它,因为您最终可能会在同一帧上多次更新同一组件。
You can use
myButton1.validateNow()
but it's use is discouraged, for you may end up having the same component update itself multiple times on the same frame.使用 validateNow() 。但是,我会谨慎使用它。使用 invalidateDisplayList() 将强制 updateDisplayList() 在下一个渲染器事件上运行。
渲染事件发生在每一帧上。 Flex 默认情况下每秒发生 24 帧。您确定需要更快地更改这些值吗?
Use validateNow() . But, I would use it sparingly. using invalidateDisplayList() will force updateDisplayList() to run on the next renderer event.
A render event happens on each frame. 24 frames happen each second by default for Flex. Are you sure need to change these values quicker?
我会为 myButton1 设置标签,然后将剩余的代码放入一个单独的方法中,并使用 callLater 调用该方法:
这样 myButton1 将在进入循环之前更新以显示新标签,因为 callLater 在事件发生后才会调用 bar队列被清除,为 myButton1 提供更新的机会。
I would set the label for myButton1, then put the remaining code into a separate method and call that method using callLater:
This way myButton1 will update to show the new label before going into your loop since callLater doesn't call bar until after the event queue is cleared, giving myButton1 a chance to update.
invalidateDisplayList() 或 valdiateNow() 会为您完成此操作,但是过度使用这些将最终导致内存泄漏。
invalidateDisplayList() or valdiateNow() will do it for you however excess of using these will end up memory leaks.