强制 Flex 更新屏幕? [英] Forcing Flex to update the screen?

查看:24
本文介绍了强制 Flex 更新屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个初学者的问题,但我终生无法弄清楚.

This may be a bit of a beginners question, but I can't for the life of me figure it out.

我正在使用 flex 为大型项目开发 GUI,特别是底部的状态栏.在我的 StatusBar 类中,有一个 ProgressBar,其他正在工作的类可以告诉它在进行时更新(更改条形完成和标签).我遇到的问题是 flex 不会更新屏幕上显示的内容,直到为时已晚,例如

I'm using flex to develop a GUI for a large project, specifically a status bar along the bottom. Within my StatusBar class is a ProgressBar, which other classes doing work can tell to update(change bar completion and label) as they progress. The problem I'm encountering is that flex won't update whats shown on the screen until it's too late, for example

ProgressBar 已初始化,完成 0%
某些类将 ProgressBar 设置为 12% 完成
某个班级做了一些工作
某个类将 ProgressBar 设置为 56% 完成

发生的事情是 12% 的完成度永远不会显示,它在工作期间只是挂在 0% 处,然后直接跳到 56% 的完成度.我试图了解 flex 组件的生命周期(失效和验证),我想我理解它并正确应用它,但它根本不起作用.我需要告诉 flex 在 some class 将它设置为 12% 完成后重绘我的 StatusBar(或至少其中的 ProgressBar),但在 some class 开始工作之前.我该怎么做?

Whats happening is the 12% done is never displaying, it just hangs at 0% during the work, then skips right to 56% done. I've tried to understand the lifecycle of a flex component (invalidation and validation), and I think I understand it and am applying it correctly, but it's not working at all. I need to tell flex to redraw my StatusBar (or at least the ProgressBar within) after some class sets it to be 12% done, but before some class starts doing its work. How do I do this?

推荐答案

正如其他答案中提到的,flash player 是单线程的,如果你不把你的工作分解成可以在单独的帧"中执行的离散块",您将在用户界面中看到跳跃和卡顿,这实际上就是您所看到的.

As mentioned in other answers, the flash player is single threaded, if you don't break up your work into discrete chunks that can be executed in separate "frames", you're going to see jumps and stutters in the ui, which is effectively what you're seeing.

如果您真的必须看到那 12% 的消息,那么仅使显示列表无效是不够的,因为在 56% 的工作完成之前显示列表没有机会更新,您必须明确中断自然设置消息后调用 validateNow() 的事件循环.

If you really must see that 12% message, then it's not enough to invalidate the display list, as the display list isn't getting a chance to update until after the 56% work has completed, you must explicitly interrupt the natural event cycle with a call to validateNow() after your message has been set.

然而,如果需要考虑性能,这并不是最好的处理方式.您可能会通过 callLater() 的司法用法来依次安排每个工作块,因为这将允许玩家在尝试下一个之前完成一个帧循环(并更新显示列表)进入您的流程.

This however is not the best way to do things if performance is of concern. You might get by with judicial usage of callLater() to schedule each chunk of work in turn, as this will allow the player to potentially complete a frame cycle (and update the display list) before attempting the next step in your process.

这篇关于强制 Flex 更新屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆