居振梁[暴龙] 2009年12月25日 星期五 22:34 | 1690次浏览 | 0条评论
http:
Key Problem: Order-invoking asynchronous events
PS:这么长时间了,这个编辑器还是这么烂。
Previous: AIR on ActionScript's own of deducting Visualizing Data [Time Series]
Related Downloads:
MSN SkyDriver Books
Visualizing Data
Source Files
VisualizingData.ConnectionAndCorrelation.tar.bz2
Related Links:
Preface: AIR on ActionScript's own of deducting
Visualizing Data
Getting Started: AIR on ActionScript's own of deducting
Visualizing Data
As you see,
ActionScript 3
is an asynchronous event-driven programming language. So you cannot suppose the completion order of several events even they are order-invoked and do the same thing, and currently there is no good example to implement a synchronous mechanism because
as3
is also a single-thread language. Perhaps you also worked out that the flash player is a multi-thread environment. Yes, so it is. That sounds good, however, only the special actions/events handlers can execute in non-main threads and it goes automatically. On another hand, I heard the non-main threads only be dispatched when all the other threads done.
That's why the document say "When the event actually happens, the event target calls each function and method registered in turn" but you can never use the endless loop that controlled by the "share variable" to indicate the
sleep
-like mechanism
. If you do this the loop will soon lead the main window forced to suspend because the event handler is waiting for the main thread done.
Sometimes this is a bad feature but don't worry. Let's think it out why this is still reasonable. Unlike other languages such as
Java
,
Flash
/
flex
or even
AIR
with
ActionScript 3
is used to build the pure GUI softwares. Almost all the functions of these softwares are driven by users, so the most time during its run time is waiting, this gives lots of points to invoke the events hanlders. Furthermore, there is a good feature
Function Expression
that alow us to write the codes in turn as if it really supports synchronous machism. So as the widely usage in frameworks itself, we can add optional parameters as the callback functions to each function or method contains the asynchronous invocation.
Returning to the original purpose (
Please review the seven stages of visualizing data descripted in chapter 1 because unlike the previous chapters this one gives you the chance to practise the entire stages
). In short, this demonstration needs some datas about the baseball seasons mined in the online website from both HTML and
javascript
formats, then drawing these datas in the window. In order to make an interaction between user and program, there also needs a
date selector component
to switch between dates. But my instance is a bit different from the original one:
Finally I show you the most key method
loadMultiURLs
here, it's used to load and parse several URLs in well-defined order.
[请直接看原文或下载的代码]
Haw-haw, I'm not interested in baseball, so my instance acts the test cases of this method (Please checking the source code
Correlation.as
at lines 89, 106, 109, 275). Frankly speaking, I am not satisfied with this method at all, but I've no better idea because the last invoked event handler is unpredictable. Do you have any opinions? Thanks!
Zeuux © 2024
京ICP备05028076号
暂时没有评论