チェンジセット 609
- コミット日時:
- 2008/06/11 20:32:34 (4 年前)
- ファイル:
-
- as3/Commands/src/commands/AsyncCommand.as (更新) (1 diff)
- as3/Commands/src/commands/BatchCommand.as (更新) (3 diffs)
- as3/Commands/src/commands/Command.as (更新) (4 diffs)
- as3/Commands/src/commands/CommandBase.as (更新) (2 diffs)
- as3/Commands/src/commands/CommandContainer.as (更新) (4 diffs)
- as3/Commands/src/commands/FrameWaitCommand.as (更新) (2 diffs)
- as3/Commands/src/commands/ICommand.as (更新) (2 diffs)
- as3/Commands/src/commands/ParallelCommand.as (更新) (3 diffs)
- as3/Commands/src/commands/SerialCommand.as (更新) (2 diffs)
- as3/Commands/src/commands/WaitCommand.as (更新) (2 diffs)
- as3/Commands/src/commands/ext/CheckCommand.as (削除)
- as3/Commands/src/commands/ext/ProcessCommand.as (更新) (1 diff)
- as3/Commands/src/commands/ext/URLLoaderCommand.as (更新) (1 diff)
凡例:
- 変更無し
- 追加
- 削除
- 更新
- コピー
- 移動
as3/Commands/src/commands/AsyncCommand.as
r232 r609 5 5 6 6 /** 7 * 「任意の非同期処理を実行し、結果を待つ」コマンド. 8 * 7 9 * Executes async function call. E.G. Loader, URLLoader, etc... 8 10 * This Command register functions event dispacher and catch their event. as3/Commands/src/commands/BatchCommand.as
r249 r609 4 4 5 5 /** 6 * ParallelCommand と SerialCommand のベースとなる抽象クラスです。 7 * このクラスが実際にインスタンス化されることはありません。 6 * ParallelCommand と SerialCommand のベースとなる抽象クラス. 7 * 8 * <p>このクラスが実際にインスタンス化されることはありません。</p> 9 * 10 * @see commands.ParallelCommand 11 * @see commands.SerialCommamd 8 12 */ 9 13 public class BatchCommand extends CommandBase … … 23 27 /** 24 28 * ICommandインターフェースを実装したコマンドを処理に追加します。 25 * @param com Command29 * @param com ICommandインターフェースを実装したコマンド。 26 30 */ 27 31 public function push(com:ICommand):void … … 32 36 33 37 /** 34 * Commandインスタンスを作成し処理に追加するショートカット関数 です。38 * Commandインスタンスを作成し処理に追加するショートカット関数。 35 39 */ 36 40 public function pushCommand(thisObject:*, func:Function, params:Array=null):void 37 41 { 38 var c:Command = new Command(thisObject, func, params); 39 push(c); 42 push(new Command(thisObject, func, params)); 40 43 } 41 44 42 45 43 46 /** 44 * WaitCommandインスタンスを作成し処理に追加するショートカット関数 です。47 * WaitCommandインスタンスを作成し処理に追加するショートカット関数。 45 48 */ 46 49 public function pushWait( delay:Number ):void 47 50 { 48 var c:WaitCommand = new WaitCommand(delay); 49 push(c); 51 push(new WaitCommand(delay)); 50 52 } 51 53 52 54 53 55 /** 54 * SerialCommandインスタンスを作成し処理に追加するショートカット関数 です。56 * SerialCommandインスタンスを作成し処理に追加するショートカット関数。 55 57 */ 56 58 public function pushSerial( commands:Array = null ):void 57 59 { 58 var c:SerialCommand = new SerialCommand(commands); 59 push(c); 60 push(new SerialCommand(commands)); 60 61 } 61 62 62 63 63 64 /** 64 * ParallelCommandインスタンスを作成し処理に追加するショートカット関数 です。65 * ParallelCommandインスタンスを作成し処理に追加するショートカット関数。 65 66 */ 66 67 public function pushParallel( commands:Array = null ):void 67 68 { 68 var c:ParallelCommand = new ParallelCommand(commands); 69 push(c); 69 push(new ParallelCommand(commands)); 70 70 } 71 71 72 72 public function pushAsync(thisObject:Object, func:Function, params:Array, eventDispatcher:EventDispatcher, eventType:String):void 73 73 { 74 var c:AsyncCommand = new AsyncCommand(thisObject, func, params, eventDispatcher, eventType); 75 push(c); 74 push(new AsyncCommand(thisObject, func, params, eventDispatcher, eventType)); 76 75 } 77 76 77 /** 78 * FrameWaitCommandインスタンスを作成し処理に追加するショートカット。 79 */ 78 80 public function pushFrameWait(frameNum:int):void 79 81 { 80 var c:FrameWaitCommand = new FrameWaitCommand(frameNum); 81 push(c); 82 push(new FrameWaitCommand(frameNum)); 82 83 } 83 84 } as3/Commands/src/commands/Command.as
r317 r609 2 2 { 3 3 /** 4 * 関数execute()をコールすることで、あらかじめ登録しておいた処理を実行します。 5 * 処理の終了後にはEvent.COMPLETEが発行されます。 4 * 「任意の関数を実行する」コマンド. 6 5 * 7 * Commandクラスの現状の課題は、インスタンスの作成時の段階で、 8 * 関数およびパラメーターが存在していなければならないことです。 9 * 将来的には関数、パラメーターに対して遅延評価を行うことのできる仕組みを実装する予定です。 6 * <p>Commandクラスを用いることで、「関数の呼び出し」という行為を変数としてやりとりするが可能となります。</p> 10 7 * 11 * @example 以下はCommandクラスの基本的な使い方です。 8 * @example 以下はCommandクラスの基本的な使い方です。この例では"Hello Command"という文字列を表示するCommandを作成し、実行しています。 12 9 * <listing version="3.0"> 13 * var command:Command = new Command(null, trace, [" "]);10 * var command:Command = new Command(null, trace, ["Hello Command"]); 14 11 * command.execute(); 15 * </listing> 12 * 13 * //Outputs 14 * //Hello Command</listing> 16 15 * 17 16 */ 18 17 public class Command extends CommandBase 19 18 { 20 protected var _thisObject : Object 19 //このthisObjectはクロージャのthisスコープをコントロールする為に、一応のこしておく。 20 protected var _thisObject : Object; 21 21 protected var _function : Function; 22 22 protected var _params : Array; … … 25 25 * 関数execute()実行時に行いたい処理を登録します。 26 26 * 27 * @param thisObject Thisとして使用されるスコープです。 AS3では指定する必要はありません。AS2との互換性の為に存在しています。27 * @param thisObject Thisとして使用されるスコープです。基本的にnullで問題ありません。クロージャおよびAS2との互換性の為に存在しています。 28 28 * @param func:Function 登録したい関数の参照。 29 29 * @param params:Array 関数実行時に渡されるパラメーター … … 32 32 { 33 33 super(); 34 _thisObject = thisObject 35 _function = func 36 _params = params 34 _thisObject = thisObject; 35 _function = func; 36 _params = params; 37 37 } 38 38 … … 46 46 override public function execute():void 47 47 { 48 if(_params){ 49 _function.apply(_thisObject, _params); 50 }else{ 51 _function.apply(_thisObject); 52 } 53 48 _function.apply(_thisObject, _params); 54 49 this.dispatchComplete(); 55 50 } as3/Commands/src/commands/CommandBase.as
r232 r609 5 5 6 6 /** 7 * commandsパッケージで使用されるコマンドのルートとなる抽象クラス。 8 * 独自のコマンドクラスを作成する場合には、基本的にこのクラスを継承してください。 7 * 全てのコマンドの基底クラス. 8 * 9 * <p>このクラスが直接使われることはありません。独自のコマンドを作成する場合には、このクラスを継承してください。</p> 9 10 */ 10 11 public class CommandBase extends EventDispatcher implements ICommand 11 12 { 12 13 /** 13 * テンプレート関数。14 * コマンドとして定義された処理を実行します. 14 15 * 15 * この関数をオーバーライドして実行したい処理を書きます。16 * 同期処理、非同期処理にかかわらず、処理の終了時には関数dispatchComplete()をコールしてください。16 * <p>この関数はテンプレート関数です。実際の実装はサブクラスで行われます。</p> 17 * <p>サブクラスの実装ではexecuteによって行われる全ての処理の終了時に、関数dispatchComplete()を呼び出してください。</p> 17 18 */ 18 public function execute():void{} 19 public function execute():void 20 { 21 //ここに実行したい処理を書く 22 dispatchComplete(); 23 } 19 24 20 25 21 26 /** 22 * テンプレート関数。 23 * 24 * この関数は将来の拡張の為に予約されています。 27 * この関数は将来の拡張の為に予約されています。. 25 28 */ 26 29 public function cancel():void{} … … 28 31 29 32 /** 30 * コマンドの終了を通知する為に、Event.COMPLETEを発行します。 33 * コマンドの終了を通知する為に、Event.COMPLETEを発行します. 34 * 35 * <p>CommandBaseのサブクラスでは、execute()で実行する処理の終了時には、 36 * 明示的にこの関数を呼び出してください</p> 31 37 */ 32 38 protected function dispatchComplete():void as3/Commands/src/commands/CommandContainer.as
r317 r609 5 5 6 6 /** 7 * 変数内にCommandインスタンスを残して参照地獄にならないように、 8 * 実行中のICommandを実装したクラスを一時的にホールドする為のクラスです。 9 * 実行終了後にICommandインスタンスへの参照は開放されます。 7 * 実行中の非同期コマンドがガベージコレクトされないよう、参照を保持するクラス. 10 8 * 11 * @example 9 * SerialCommand, ParallelCommand, AsyncCommandなど非同期のコマンドが、実行中にガベージコレクションされるのを防ぐのに用いられます。 10 * 実行終了後、CommandContainerに格納されたICommandインスタンスへの参照は開放されます。 11 * 12 * @example 以下の例ではSerialCommandを実行し、その終了までSerialCommandの参照を保持します。 12 13 * <listing version="3.0"> 13 14 * var serialCommand = new SerialCommand([ 14 15 * new Command(null, trace, ["test"]); 15 * new WaitCommand(1000 );16 * new WaitCommand(10000); 16 17 * new Command(null, trace, ["test"]); 17 18 * ]) … … 22 23 public class CommandContainer 23 24 { 24 protected static var commandDict:Dictionary25 protected static var _commandDict:Dictionary 25 26 protected static var _numCommands:int = 0; 26 27 27 public static function execute(command:ICommand):ICommand 28 /** 29 * 引数として渡したICommandを実行し、処理が終了するまで参照を保持します。 30 * 31 * コマンドの終了時、CommandContainer内に保持された参照は破棄されます。 32 */ 33 public static function execute(command:ICommand):void 28 34 { 29 if( commandDict==null)30 commandDict = new Dictionary();35 if(_commandDict==null) 36 _commandDict = new Dictionary(); 31 37 32 if( commandDict[command]){38 if(_commandDict[command]){ 33 39 throw new Error("CommandContainer.execute() this command is alrealdy registerd"); 34 40 } 35 41 36 commandDict[command] = command;42 _commandDict[command] = command; 37 43 _numCommands++; 38 44 39 45 command.addEventListener(Event.COMPLETE, executeHandler); 40 46 command.execute(); 41 42 return command;43 47 } 44 48 49 50 //デバッグ用、現在実行中のコマンドの数を返す。 45 51 public static function get numCommands():int 46 52 { … … 48 54 } 49 55 56 57 //デバッグ用、現在実行中のコマンドをダンプする。 50 58 public static function dump():void 51 59 { 52 for (var prop:* in commandDict){53 trace( commandDict[prop]);60 for (var prop:* in _commandDict){ 61 trace(_commandDict[prop]); 54 62 } 55 63 } 56 64 65 66 /* 67 コマンドの終了のハンドリング。 68 終了したコマンドのリスナ解除と、参照の廃棄を行う。 69 */ 57 70 protected static function executeHandler(e:Event):void 58 71 { … … 61 74 _numCommands--; 62 75 63 //trace("CommandComtainer.complete",_numCommands); 64 65 //すぐ消さない。1フレームぐらい待ったほうがいい?? 66 commandDict[command] = null; 67 delete commandDict[command]; 76 //すぐ消さないずに1フレームぐらい待ったほうがいいのか?? 77 _commandDict[command] = null; 78 delete _commandDict[command]; 68 79 } 69 80 } as3/Commands/src/commands/FrameWaitCommand.as
r305 r609 6 6 7 7 /** 8 * WaitCommandのonEnterFrame版 9 * 指定フレーム数経過したらEvent.COMPLETEを発行する 8 * 「指定フレーム待つ」コマンド. 9 * 10 * <p>WaitCommandのonEnterFrame版です。指定フレーム数経過したらEvent.COMPLETEを発行します。</p> 11 * 12 * <p>WaitCommandの使用する為には初期化が必要です。初回クラス使用時の前にあらかじめ<code>WaitCommand.init</code>を呼び出してください。</p> 13 * 14 * @see commamds.WaitCommand 10 15 */ 11 16 public class FrameWaitCommand extends CommandBase … … 21 26 } 22 27 28 /** 29 * WaitCommandがEvent.ENTER_FRAMEを受け取れるように初期化します. 30 * 31 * 初回使用時の前に必ず呼び出してください。 32 * 33 * @params stage ステージの参照 34 */ 35 public static function init( stage:Stage ):void 36 { 37 enterFrameBeacon = stage; 38 } 39 23 40 override public function execute():void 24 41 { 25 42 if(!enterFrameBeacon) 26 throw new Error("FrameWaitCommand. enterFrameBeacon should be set to receive Event.ENTER_FRAME");43 throw new Error("FrameWaitCommand.init should be called before first execution."); 27 44 enterFrameBeacon.addEventListener(Event.ENTER_FRAME, _enterFrameHandler, false, 0, true); 28 45 } as3/Commands/src/commands/ICommand.as
r232 r609 3 3 4 4 /** 5 * commandsライブラリで使用される共通インターフェース 。5 * commandsライブラリで使用される共通インターフェース. 6 6 */ 7 7 public interface ICommand … … 26 26 */ 27 27 function execute():void 28 29 function cancel():void 28 30 } 29 31 } as3/Commands/src/commands/ParallelCommand.as
r249 r609 4 4 5 5 /** 6 * Executes series of commands at once, and wait for all complement. 7 * After execution, this dispatches Event.COMPLETE. 8 * Used for multiple data loading. 6 * 「全ての子コマンドを同時に実行し、その全ての終了を待つ」コマンド. 9 7 * 8 * <p>登録された複数のコマンドを全て同時に実行し、その全てのコマンドが終了するとEvent.COMPLETEが発行されます。 9 * 複数のデータが全てロードされるのを待つ時等に用いられます</p> 10 * 11 * @example 以下の例では、「文字の表示」「1秒待ち」「文字を表示」を同時に実行し、全てが終了した時点(つまり1秒後)にEvent.COMPLETEを発行します。" 12 * <listing version="3.0"> 10 13 * var coms : Array = [ 11 14 * new Command("hello"), … … 15 18 * var pCom : ParallelCommand = new ParallelCommand( coms ); 16 19 * pCom.addEventListener(Event.COMPLETE, _commandCompleteHandler); 17 * pCom.execute();18 20 * 21 * CommandContainer.execute( pCom);</listing> 22 * 23 * @see commands.SerialCommand 24 * @see commands.CommandContainer 19 25 */ 20 26 public class ParallelCommand extends BatchCommand … … 24 30 super( commandArray ); 25 31 } 26 27 28 29 32 30 33 as3/Commands/src/commands/SerialCommand.as
r249 r609 4 4 5 5 /** 6 * 登録された複数のコマンドを1つづつ順番に実行、終了させていきます。 7 * 最後のコマンドの終了時にEvent.COMPLETEを発行します。 6 * 「全ての子コマンドを1つづつ実行・終了する」コマンド. 8 7 * 9 * SerialCommandインスタンスは1回だけの使用を前提とし、再利用は考慮されていません。 10 * 同じ処理を繰り返して行いたい場合には、処理の度に新しいSerialCommandインスタンスを作成してください。 8 * <p>登録された複数のコマンドを1つづつ順番に実行、終了させていきます。 9 * 最後のコマンドの終了時にEvent.COMPLETEを発行します。</p> 10 * 11 * <p>SerialCommandインスタンスは1回だけの使用を前提とし、再利用は考慮されていません。 12 * 同じ処理を繰り返して行いたい場合には、処理の度に新しいSerialCommandインスタンスを作成してください。</p> 11 13 * 12 14 * @example 以下のコードは、hello と表示し、1秒後に world と表示します。 … … 19 21 * var sCom : SerialCommand = new SerialCommand( ar ); 20 22 * sCom.addEventListener(Event.COMPLETE, _commandExecuteHandler); 21 * sCom.execute(); 23 * 24 * //ガベージコレクトされないよう、CommandContainerを用いて実行する。 25 * CommandContainer.execute(sCom); 22 26 * </listing> 23 27 * 28 * @see commands.CommandContainer 24 29 */ 25 30 public class SerialCommand extends BatchCommand as3/Commands/src/commands/WaitCommand.as
r250 r609 5 5 6 6 /** 7 * Dispatches Event.COMPLETE event after certain delay. 8 * Used for taking a break between multiple commands. 7 * 「指定したミリ秒待機する」コマンド. 9 8 * 10 * @usage 11 * var command : WaitCommand = new WaitCommand(1000); 12 * command.execute(); 9 * <p>SerialCommandやParallelCommand等のバッチ処理系のコマンドにインターバルを挟む為に用います。</p> 10 * 11 * @example 以下はWaitCommandクラスの基本的な使い方です。この例では関数executeを実行して1秒後に、Event.COMPLETEが発行されます。 12 * <listing version="3.0"> 13 * var command:ICommand = new WaitCommand(1000); 14 * command.addEventListener(Event.COMPLETE, function():void{ 15 * trace("Command Completed"); 16 * }); 17 * CommandContainer.execute( command );</listing> 18 * 19 * @example この例ではSerialCommandを用いて1秒待った後に文字列を表示しています。 20 * <listing version="3.0"> 21 * var serial:SerialCommand = new SerialCommand(); 22 * serial.push( new WaitCommand( 1000 )); 23 * serial.push( new Command( null, trace, "Hello World" ); 24 * 25 * CommandContainer.execute( serial );</listing> 26 * 27 * @see commands.SerialCommand 28 * @see commands.ParallelCommand 29 * @see commands.CommandContainer 13 30 */ 14 31 public class WaitCommand extends CommandBase … … 18 35 19 36 /** 20 * dispatches Event.COMPLETE event after certain delay. 21 * @param millisecond duration for delay 37 * 「指定したミリ秒だけ待つ」コマンド。 38 * 39 * @param 待ち時間のミリ秒。 22 40 */ 23 41 public function WaitCommand( delay:Number = 1000) as3/Commands/src/commands/ext/ProcessCommand.as
r245 r609 7 7 8 8 /** 9 * 指定の関数が true を返すまで、 定期的にコールするコマンド。10 * スタックの消化や擬似スレッド等を行いたい場合に使う9 * 指定の関数が true を返すまで、値をチェックするコールするコマンド。 10 * 何かの処理の処理や、条件が整うまでスタックの消化や擬似スレッド等を行いたい場合に使う 11 11 */ 12 12 public class ProcessCommand extends CommandBase as3/Commands/src/commands/ext/URLLoaderCommand.as
r317 r609 1 1 package commands.ext 2 2 { 3 import commands.Command; 3 import commands.CommandBase; 4 5 import flash.events.Event; 6 import flash.events.IOErrorEvent; 4 7 import flash.net.URLLoader; 8 import flash.net.URLLoaderDataFormat; 5 9 import flash.net.URLRequest; 6 import flash.net.URLLoaderDataFormat;7 import flash.events.Event;8 import commands.CommandBase;9 import flash.events.IOErrorEvent;10 10 import flash.net.URLVariables; 11 11

