Flex addEventListener - 如何在调用事件期间刷新屏幕?
我似乎无法找到我认为是常见问题的答案。
我想做的是: 1. 显示打开文件对话框 2. 处理选择的文件 3. 在处理文件期间,向用户报告进度
我定义了一个文件,并且正在使用 browserForOpen 和 AddEventListener:
public var fileInput:File = new File();
fileInput.browseForOpen("Open file",[filter]);
fileInput.addEventListener(Event.SELECT, onFileSelect);
// Step 2 - function gets called to process the file
private function onFileSelect(e:Event):void
{
// Step 3 - do some processing, and at intervals report progress to the screen
}
我的问题是 - 在函数完成之前,事件侦听器内对屏幕的任何更改都不会完成。
任何帮助将不胜感激, 谢谢
I can't seem to find the answer to what I would have thought was a common problem.
What I want to do this is:
1. Show the Open File Dialog
2. Process the file selected
3. During processing the file, report progress to the User
I have a file defined, and am using the browseForOpen and AddEventListener:
public var fileInput:File = new File();
fileInput.browseForOpen("Open file",[filter]);
fileInput.addEventListener(Event.SELECT, onFileSelect);
// Step 2 - function gets called to process the file
private function onFileSelect(e:Event):void
{
// Step 3 - do some processing, and at intervals report progress to the screen
}
My issue is - any changes to the screen within the event listener do not get done until the function is complete.
Any help would be appreciated,
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许启动一个计时器并让它检查变量的状态(表示处理进度)作为一个单独的运行函数,它不会倾向于等待父函数。
[明确地说,我是说从计时器中调用一个单独的函数。]
但我倾向于同意 Flextras.com 的观点,因为大多数时候我这样做的处理时间都是毫秒,所以只是没有被看到。
Start a timer perhaps and let it check status of a variable(that denotes processing progress) as a separate running function it would not be predisposed to waiting on the parent function.
[ to be clear Im saying call a sperate function from the timer.]
But I am inclined to agree with Flextras.com in that most times I have done this the processing was milliseconds so just didnt get seen.
在步骤 3 中,如果您正在执行一些 CPU 密集型工作(例如巨大的 xml 解析),那么您可能会看到此未更新问题。由于 Flex 是单线程的,因此您最好利用绿色线程概念。
您可以在此处阅读有关绿色线程的信息。
In Step 3, if you are doing some cpu intensive job(like huge xml parsing), then you might be seeing this NOT updating problem. As Flex is single threaded, you better make use of Green threading concept.
You can read about Green Threading here.