| 1 |
/** |
|---|
| 2 |
* |
|---|
| 3 |
* |
|---|
| 4 |
**/ |
|---|
| 5 |
package |
|---|
| 6 |
{ |
|---|
| 7 |
import flash.display.Bitmap; |
|---|
| 8 |
import flash.net.URLRequest; |
|---|
| 9 |
import lib.cloud.CloudView; |
|---|
| 10 |
import lib.loading.LoadingProgressView; |
|---|
| 11 |
import lib.core.PassiveMovieClip; |
|---|
| 12 |
import org.libspark.display.LoaderThread; |
|---|
| 13 |
import org.libspark.net.URLLoaderThread; |
|---|
| 14 |
import org.libspark.thread.Thread; |
|---|
| 15 |
//import org.libspark.utils.concurrent.ParallelExecutor; |
|---|
| 16 |
import org.libspark.utils.concurrent.SerialExecutor; |
|---|
| 17 |
|
|---|
| 18 |
/** |
|---|
| 19 |
* 全体の動きを制御するクラス |
|---|
| 20 |
**/ |
|---|
| 21 |
internal class ApplicationThread extends Thread |
|---|
| 22 |
{ |
|---|
| 23 |
/** |
|---|
| 24 |
* Applicationのインスタンス |
|---|
| 25 |
**/ |
|---|
| 26 |
private var _view:Application; |
|---|
| 27 |
|
|---|
| 28 |
/** |
|---|
| 29 |
* CloudViewのインスタンス |
|---|
| 30 |
**/ |
|---|
| 31 |
private var _cloud:CloudView; |
|---|
| 32 |
|
|---|
| 33 |
/** |
|---|
| 34 |
* URLLoaderThreadのインスタンス(XMLロード用) |
|---|
| 35 |
*/ |
|---|
| 36 |
private var _xmlLoadThread:URLLoaderThread; |
|---|
| 37 |
|
|---|
| 38 |
/** |
|---|
| 39 |
* SerialExecutorのインスタンス(画像ロード用) |
|---|
| 40 |
**/ |
|---|
| 41 |
private var _imageLoadThread:SerialExecutor; |
|---|
| 42 |
|
|---|
| 43 |
/** |
|---|
| 44 |
* 初期化を行う |
|---|
| 45 |
* |
|---|
| 46 |
* @param p_view Applicationのインスタンス |
|---|
| 47 |
**/ |
|---|
| 48 |
public function ApplicationThread(p_view:Application) |
|---|
| 49 |
{ |
|---|
| 50 |
_view = p_view; |
|---|
| 51 |
} |
|---|
| 52 |
|
|---|
| 53 |
/** |
|---|
| 54 |
* スレッドの初期化を行う |
|---|
| 55 |
**/ |
|---|
| 56 |
protected override function initialize():void |
|---|
| 57 |
{ |
|---|
| 58 |
// setup loading progress. |
|---|
| 59 |
var l:LoadingProgressView = _view.addChild(new LoadingProgressView({ |
|---|
| 60 |
name: 'Loading', |
|---|
| 61 |
x: _view.stage.stageWidth / 2, |
|---|
| 62 |
y: _view.stage.stageHeight / 2 |
|---|
| 63 |
})) as LoadingProgressView; |
|---|
| 64 |
// show loading. |
|---|
| 65 |
l.showThread.begin(); |
|---|
| 66 |
_xmlLoadThread = new URLLoaderThread(new URLRequest(_view.targetUrl)); |
|---|
| 67 |
_xmlLoadThread.begin(); |
|---|
| 68 |
_xmlLoadThread.join(); |
|---|
| 69 |
} |
|---|
| 70 |
|
|---|
| 71 |
protected override function execute():void |
|---|
| 72 |
{ |
|---|
| 73 |
switchExecuteMethod(hoge); |
|---|
| 74 |
_imageLoadThread = new SerialExecutor(); |
|---|
| 75 |
var rootNode:XML, location:XML; |
|---|
| 76 |
rootNode = new XML(_xmlLoadThread.loader.data); |
|---|
| 77 |
for each (location in rootNode.item.location) |
|---|
| 78 |
{ |
|---|
| 79 |
_imageLoadThread.addThread(new LoaderThread(new URLRequest(location.text()))); |
|---|
| 80 |
} |
|---|
| 81 |
_imageLoadThread.begin(); |
|---|
| 82 |
_imageLoadThread.join(); |
|---|
| 83 |
} |
|---|
| 84 |
|
|---|
| 85 |
private function hoge():void |
|---|
| 86 |
{ |
|---|
| 87 |
switchExecuteMethod(hige); |
|---|
| 88 |
// hide loading. |
|---|
| 89 |
LoadingProgressView(_view.getChildByName('Loading')).hideThread.begin(); |
|---|
| 90 |
var i:int, b:Bitmap, d:Array = []; |
|---|
| 91 |
for (i = 0; i < _imageLoadThread.numThreads; i++) |
|---|
| 92 |
{ |
|---|
| 93 |
b = LoaderThread(_imageLoadThread.getThreadAt(i)).loader.content as Bitmap; |
|---|
| 94 |
d.push(b); |
|---|
| 95 |
} |
|---|
| 96 |
_cloud = _view.addChild(new CloudView(d)) as CloudView; |
|---|
| 97 |
} |
|---|
| 98 |
|
|---|
| 99 |
private function hige():void |
|---|
| 100 |
{ |
|---|
| 101 |
_cloud.actionThread.begin(); |
|---|
| 102 |
} |
|---|
| 103 |
|
|---|
| 104 |
protected override function finalize():void |
|---|
| 105 |
{ |
|---|
| 106 |
_view = null; |
|---|
| 107 |
_cloud = null; |
|---|
| 108 |
trace('finalized.'); |
|---|
| 109 |
} |
|---|
| 110 |
} |
|---|
| 111 |
} |
|---|