居振梁[暴龙]

居振梁[暴龙]的博客

他的个人主页  他的博客

AIR on ActionScript's own of deducting Visualizing Data [5]

居振梁[暴龙]  2009年12月25日 星期五 22:34 | 1696次浏览 | 0条评论

http://wargrey.blogspot.com/2009/12/air-on-actionscripts-own-of-deducting.html
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

Before we start, let me have an introduction since the previous posts are posted in my Chinese blog whose functions have been transfered here. These series of posts are used to record my process of re-implementingthe examples demonstrated in book Visualizing Data using pure and basic ActionScript 3 (only using its standard frameworks, and without using amxml ) running on AIR 1.5. As always, I will not nag the knowledge that you can find in the book or API reference.

The context of this post corresponds the chapter 5 Connection and Correlation  of the original book. From this chapter on, the demonstration becomes interesting because it is not only the simple representation but including the data mining. So this demonstration is more practical if you like baseball seasons, or you can program something else like this.

ConnectionAndCorrelation

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:

1.All the datas in my instance are mining by pure ActionScript 3 codes instead of by hand. The book does not suggest handing by code, but to speak frankly, this is my first time to data mining, and it's a good chance to accumulate my code frameworks (and test cases), so I parsed the datas all by code. Of course, these datas are saved to disk for the next accessing if they were first downloaded.
2.The original demonstration only cares about the datas of current year. But... The first time I read this chapter I had misunderstood the parameters of the data selector component . Until I coded for it my instance has supported the multi years, and I think this feature is more useful, so I add two more keys shortcuts to switch the current year . Because of the different numbers of dates I have to widen the width of main window.
3.In the original demonstration, the lines drawing to connect the teams and salaries are variant in size.But obviously the salaries are ordered, and the lines must be smaller and smaller from up to down. This looks ugly, so I gave parameters maximum Thickness and minimum Thickness the same value.
4.Because AIR programs will not be executed in the browers. So I ignored the entire section Deployment Consideration .
5.Some other fine turning.


Finally I show you the most key method loadMultiURLs here, it's used to load and parse several URLs in well-defined order.

 
 
 
 
 
  [请直接看原文或下载的代码]
 
 
  


 

I am sorry these codes are ugly for reading, but there is no overloading mechanism in ActionScript 3 . This complicates the handing of parameters, actually my codes are easy to understand if you have the knowledge of Closure .


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哲思注册吗?现在 注册 !

暂时没有评论

Zeuux © 2024

京ICP备05028076号