| 1 |
/* |
|---|
| 2 |
* ActionScript Thread Library |
|---|
| 3 |
* |
|---|
| 4 |
* Licensed under the MIT License |
|---|
| 5 |
* |
|---|
| 6 |
* Copyright (c) 2008 BeInteractive! (www.be-interactive.org) and |
|---|
| 7 |
* Spark project (www.libspark.org) |
|---|
| 8 |
* |
|---|
| 9 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|---|
| 10 |
* of this software and associated documentation files (the "Software"), to deal |
|---|
| 11 |
* in the Software without restriction, including without limitation the rights |
|---|
| 12 |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|---|
| 13 |
* copies of the Software, and to permit persons to whom the Software is |
|---|
| 14 |
* furnished to do so, subject to the following conditions: |
|---|
| 15 |
* |
|---|
| 16 |
* The above copyright notice and this permission notice shall be included in |
|---|
| 17 |
* all copies or substantial portions of the Software. |
|---|
| 18 |
* |
|---|
| 19 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|---|
| 20 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|---|
| 21 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|---|
| 22 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|---|
| 23 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|---|
| 24 |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|---|
| 25 |
* THE SOFTWARE. |
|---|
| 26 |
* |
|---|
| 27 |
*/ |
|---|
| 28 |
package org.libspark.thread |
|---|
| 29 |
{ |
|---|
| 30 |
import flash.display.MovieClip; |
|---|
| 31 |
import flash.events.Event; |
|---|
| 32 |
|
|---|
| 33 |
/** |
|---|
| 34 |
* EnterFrameThreadExecutor クラスは IThreadExecutor インターフェイスの実装クラスで、 |
|---|
| 35 |
* フレーム実行のタイミングでスレッドを実行します. |
|---|
| 36 |
* |
|---|
| 37 |
* @author yossy:beinteractive |
|---|
| 38 |
*/ |
|---|
| 39 |
public class EnterFrameThreadExecutor implements IThreadExecutor |
|---|
| 40 |
{ |
|---|
| 41 |
/** |
|---|
| 42 |
* 新しい EnterFrameThreadExecutor クラスのインスタンスを作成します |
|---|
| 43 |
*/ |
|---|
| 44 |
public function EnterFrameThreadExecutor() |
|---|
| 45 |
{ |
|---|
| 46 |
} |
|---|
| 47 |
|
|---|
| 48 |
private var _clip:MovieClip; |
|---|
| 49 |
|
|---|
| 50 |
/** |
|---|
| 51 |
* @inheritDoc |
|---|
| 52 |
*/ |
|---|
| 53 |
public function start():void |
|---|
| 54 |
{ |
|---|
| 55 |
if (_clip != null) { |
|---|
| 56 |
return; |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
_clip = new MovieClip(); |
|---|
| 60 |
_clip.addEventListener(Event.ENTER_FRAME, enterFrameHandler); |
|---|
| 61 |
} |
|---|
| 62 |
|
|---|
| 63 |
/** |
|---|
| 64 |
* @inheritDoc |
|---|
| 65 |
*/ |
|---|
| 66 |
public function stop():void |
|---|
| 67 |
{ |
|---|
| 68 |
if (_clip == null) { |
|---|
| 69 |
return; |
|---|
| 70 |
} |
|---|
| 71 |
|
|---|
| 72 |
_clip.removeEventListener(Event.ENTER_FRAME, enterFrameHandler); |
|---|
| 73 |
_clip = null; |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
/** |
|---|
| 77 |
* フレーム実行ハンドラ |
|---|
| 78 |
* |
|---|
| 79 |
* @param e イベント |
|---|
| 80 |
* @private |
|---|
| 81 |
*/ |
|---|
| 82 |
private function enterFrameHandler(e:Event):void |
|---|
| 83 |
{ |
|---|
| 84 |
Thread.executeAllThreads(); |
|---|
| 85 |
} |
|---|
| 86 |
} |
|---|
| 87 |
} |
|---|