root/Theme-2/nobu/src/App2Thread.as

Revision 31, 4.3 kB (checked in by nobu, 9 months ago)

modified some files.

Line 
1 /**
2  *
3  **/
4 package
5 {
6     import flash.display.Bitmap;
7     import flash.net.URLRequest;
8     import lib.papervision3d.Papervision3DThread;
9     import org.libspark.display.LoaderThread;
10     import org.libspark.net.URLLoaderThread;
11     import org.libspark.thread.Thread;
12     import org.libspark.tweener.TweenerThread;
13     import org.libspark.utils.concurrent.SerialExecutor;
14
15     /**
16      *  アプリケーション全体を制御するメインスレッド
17      **/
18     internal class App2Thread extends Thread
19     {
20         /**
21          *  App2のインスタンス
22          **/
23         private var _view:App2;
24
25         /**
26          *  Papervision3Dレンダリング用スレッド
27          **/
28         private var _pv3dThread:Papervision3DThread;
29
30         /**
31          *  XML取得用スレッド
32          **/
33         private var _xmlLoadThread:URLLoaderThread;
34
35         /**
36          *
37          **/
38         private var _imageLoadThread:SerialExecutor;
39
40         /**
41          *  コンストラクタ
42          *
43          *  @param  p_view  App2のインスタンス
44          **/
45         public function App2Thread(p_view:App2)
46         {
47             _view = p_view;
48             _pv3dThread = new Papervision3DThread(_view);
49         }
50
51         /**
52          *  スレッドの初期化を行う
53          *
54          *  Papervision3Dスレッドの起動
55          **/
56         protected override function initialize():void
57         {
58             _pv3dThread.begin();
59         }
60
61         /**
62          *  XMLの取得
63          **/
64         protected override function execute():void
65         {
66             //  次の処理を指定
67             switchExecuteMethod(loadImages);
68             //  スレッドの生成と起動
69             _xmlLoadThread = new URLLoaderThread(new URLRequest(_view.targetUrl));
70             _xmlLoadThread.begin();
71             //  処理が終わるまで待つ
72             _xmlLoadThread.join();
73         }
74
75         /**
76          *  画像の取得
77          */
78         private function loadImages():void
79         {
80             //  次の処理を指定
81             switchExecuteMethod(parseImages);
82             //  ローディングの切り替え
83             new TweenerThread(_pv3dThread.loadingCube, {
84                 rotationY: 270,
85                 time: 1.0,
86                 transition: "easeOutSine"
87             }).begin();
88
89             //  XMLのパースと画像の取得
90             _imageLoadThread = new SerialExecutor();
91             var rootNode:XML, location:XML;
92             rootNode = new XML(_xmlLoadThread.loader.data);
93             for each (location in rootNode.item.location)
94             {
95                 _imageLoadThread.addThread(new LoaderThread(new URLRequest(location.text())));
96             }
97             //  スレッドの起動
98             _imageLoadThread.begin();
99             //  処理が終わるまで待つ
100             _imageLoadThread.join();
101         }
102
103         /**
104          *
105          *
106          **/
107         private function parseImages():void
108         {
109             switchExecuteMethod(hideLoadingCube);
110             var i:int, thread:LoaderThread, data:Array = [];
111             for (i = 0; i < _imageLoadThread.numThreads; i++)
112             {
113                 thread = LoaderThread(_imageLoadThread.getThreadAt(i));
114                 data.push(Bitmap(thread.loader.content));
115             }
116             _pv3dThread.data = data;
117         }
118
119         /**
120          *
121          *
122          **/
123         private function hideLoadingCube():void
124         {
125             //  次の処理を指定
126             switchExecuteMethod(forever);
127             var hideThread = new SerialExecutor();
128             //  ローディングの切り替え
129             hideThread.addThread(new TweenerThread(_pv3dThread.loadingCube, {
130                 rotationY: 360,
131                 time: 1.0,
132                 transition: "easeOutSine"
133             }));
134             hideThread.addThread(new TweenerThread(_pv3dThread.loadingCube, {
135                 z: -1000,
136                 time: 1.0,
137                 transition: "easeOutSine"
138             }));
139             hideThread.begin();
140             hideThread.join();
141         }
142
143         /**
144          *
145          *
146          **/
147         private function forever():void
148         {
149             _pv3dThread.start();
150         }
151
152         protected override function catchError(thread:Thread, error:Error):void
153         {
154             trace(error);
155             terminate();
156         }
157     }
158 }
Note: See TracBrowser for help on using the browser.