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

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

问题描述



我使用flex来开发一个新手的问​​题,但是我不能为我的生活弄明白。一个大型项目的GUI,特别是底部的状态栏。在我的StatusBar类中有一个ProgressBar,在进行的过程中,其他正在工作的类可以告诉更新(更改栏完成和标签)。我遇到的问题是,flex将不会更新屏幕上显示的内容,例如

ProgressBar已初始化,0%已完成

某些类将ProgressBar设置为完成12%

某些类执行某些工作
有些类将ProgressBar设置为56%完成



发生什么是12%完成是从不显示的,它只是挂在0%,然后跳到56%。我试图理解flex组件的生命周期(失效和验证),我想我理解它,并正确应用它,但它根本不工作。我需要告诉flex重绘我的StatusBar(或至少ProgressBar之内)之后一些类设置为12%完成,但之前一些类开始工作。如何做到这一点?

解决方案

正如其他答案中所提到的,flash player是单线程的,如果你没有破解把你的工作分成几块,可以在不同的框架中执行,你会看到用户界面中的跳跃和口吃,这实际上是你看到的。



如果你真的必须看到这个12%的信息,那么显示列表无效,因为显示列表没有机会更新,直到56%的工作完成之后,你必须明确地中断自然事件循环,在你的消息被设置后调用 validateNow()

然而这并不是最好的如果表现令人担忧的话,可以采取办法。你可以通过司法使用 callLater()来依次安排每个工作块,因为这将允许玩家潜在地完成一个帧周期(并更新显示列表),然后再尝试进行下一步。


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

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 initialized, 0% done
some class sets the ProgressBar to be 12% done
some class does some work
some class sets the ProgressBar to be 56% done

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?

解决方案

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.

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.

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天全站免登陆