チェンジセット 231
- コミット日時:
- 2008/02/05 17:15:17 (4 年前)
- ファイル:
-
- as3/Commands/src/AsyncCommand.as (更新) (3 diffs)
- as3/Commands/src/BatchCommand.as (追加)
- as3/Commands/src/Command.as (更新) (3 diffs)
- as3/Commands/src/CommandBase.as (更新) (1 diff)
- as3/Commands/src/CommandContainer.as (追加)
- as3/Commands/src/FrameWaitCommand.as (追加)
- as3/Commands/src/ICommand.as (更新) (2 diffs)
- as3/Commands/src/ParallelCommand.as (更新) (2 diffs)
- as3/Commands/src/SerialCommand.as (更新) (3 diffs)
- as3/Commands/src/ext/CheckCommand.as (追加)
- as3/Commands/src/ext/LoaderCommand.as (更新) (4 diffs)
凡例:
- 変更無し
- 追加
- 削除
- 更新
- コピー
- 移動
as3/Commands/src/AsyncCommand.as
r200 r231 5 5 6 6 /** 7 * データのロードやアニメーション等、非同期の処理を行う場合のコマンド 8 * 引数にイベントを追加できる。 7 * Executes async function call. E.G. Loader, URLLoader, etc... 8 * This Command register functions event dispacher and catch their event. 9 * After complete command, this dispaches Event.COMPLETE 9 10 * 10 * URLLoader等の非同期な機能に対してコマンドを実行できる。 11 * @usage 12 * 13 * var loader:URLLoader = new URLLoader(); 14 * var command:ICommand = new AsyncCommand(loader, loader.load, [new URLRequest(url);], loader.loaderContent, Event.COMPLETE); 15 * command.addEventListener(Event.COMPLETE, _comandCompleteHandler); 16 * command.execute(); 11 17 */ 12 18 public class AsyncCommand extends Command … … 16 22 17 23 /** 18 * @param thisObject thisスコープとなるオブジェクト19 * @param func 実行される関数20 * @param eventDispatcher 関数の処理の完了を通知するイベント発行者21 * @param 終了通知のイベントのタイプ24 * @param thisObject Scpoe used as This 25 * @param func Function for execute 26 * @param EventDispatcher Object that dispaches functions complete event. 27 * @param Type of Event for EventDispatcher. 22 28 */ 23 29 public function AsyncCommand(thisObject:Object, func:Function, params:Array, eventDispatcher:EventDispatcher, eventType:String) … … 37 43 protected function executeCompleteHandler( e:Event ):void 38 44 { 39 //_eventDispatcher.removeEventListener(_eventType, onExecute);45 _eventDispatcher.removeEventListener(_eventType, executeCompleteHandler); 40 46 this.dispatchComplete(); 41 47 } as3/Commands/src/Command.as
r203 r231 2 2 { 3 3 /** 4 * Executes passed function, when execute() is called.5 * After execution, this dispaches Event.COMPLETE.4 * 関数execute()をコールすることで、あらかじめ登録しておいた処理を実行します。 5 * 処理の終了後にはEvent.COMPLETEが発行されます。 6 6 * 7 * @usage 7 * Commandクラスの現状の課題は、インスタンスの作成時の段階で、 8 * 関数およびパラメーターが存在していなければならないことです。 9 * 将来的には関数、パラメーターに対して遅延評価を行うことのできる仕組みを実装する予定です。 8 10 * 9 * var com : Command = new Command( null, trace, ["hellow world"] ); 10 * com.execute(); 11 * @example 以下はCommandクラスの基本的な使い方です。 12 * <listing version="3.0"> 13 * var command:Command = new Command(null, trace, [""]); 14 * command.execute(); 15 * </listing> 11 16 * 12 17 */ … … 18 23 19 24 /** 20 * @param thisObject:Object Scope that is used as "this" 21 * @param func:Function Function will be executed 22 * @param params:Array Parameters will be passed to function 25 * 関数execute()実行時に行いたい処理を登録します。 26 * 27 * @param thisObject Thisとして使用されるスコープです。AS3では指定する必要はありません。AS2との互換性の為に存在しています。 28 * @param func:Function 登録したい関数の参照。 29 * @param params:Array 関数実行時に渡されるパラメーター 23 30 */ 24 31 public function Command(thisObject:Object, func:Function, params:Array=null) … … 30 37 } 31 38 39 40 /** 41 * コンストラクタで登録した処理を実行します。 42 * 43 * @eventType Event.COMPLETE 44 */ 32 45 override public function execute():void 33 46 { as3/Commands/src/CommandBase.as
r203 r231 5 5 6 6 /** 7 * Abstract class for all commands package. 7 * commandsパッケージで使用されるコマンドのルートとなる抽象クラス。 8 * 独自のコマンドクラスを作成する場合には、基本的にこのクラスを継承してください。 8 9 */ 9 10 public class CommandBase extends EventDispatcher implements ICommand 10 11 { 11 12 /** 12 * Template function.13 * テンプレート関数。 13 14 * 14 * Simply override this function with your own processing, after call dispatchComplete() function. 15 * この関数をオーバーライドして実行したい処理を書きます。 16 * 同期処理、非同期処理にかかわらず、処理の終了時には関数dispatchComplete()をコールしてください。 15 17 */ 16 18 public function execute():void{} 17 19 18 20 19 //cancel commands 21 /** 22 * テンプレート関数。 23 * 24 * この関数は将来の拡張の為に予約されています。 25 */ 20 26 public function cancel():void{} 21 27 22 28 23 29 /** 24 * dispatches event after command completation.30 * コマンドの終了を通知する為に、Event.COMPLETEを発行します。 25 31 */ 26 32 protected function dispatchComplete():void as3/Commands/src/ICommand.as
r203 r231 3 3 4 4 /** 5 * Interface for Command Library 6 * 7 * C A U T I O N 8 * After command execution, you must dispatch Event.COMPLETE 5 * commandsライブラリで使用される共通インターフェース。 9 6 */ 10 7 public interface ICommand … … 25 22 ):void 26 23 24 /** 25 * @eventType Event.COMPLETE 同期、非同期に関わらずexecuteによって行われる処理の終了時にEvent.Completeイベントを発行してください。 26 */ 27 27 function execute():void 28 28 } as3/Commands/src/ParallelCommand.as
r203 r231 4 4 5 5 /** 6 * コマンドを同時に実行し、全てが終了したらCompleteイベントを発行する。 7 * 複数のデータロード、インスタンス初期化などの待ちに使う。 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. 8 9 * 9 10 * var coms : Array = [ … … 13 14 * 14 15 * var pCom : ParallelCommand = new ParallelCommand( coms ); 16 * pCom.addEventListener(Event.COMPLETE, _commandCompleteHandler); 15 17 * pCom.execute(); 16 18 * 17 19 */ 18 public class ParallelCommand extends CommandBase20 public class ParallelCommand extends BatchCommand 19 21 { 20 protected var _commands:Array 21 protected var _index:Number 22 23 public function ParallelCommand( commandArray:Array ):void 22 public function ParallelCommand( commandArray:Array ) 24 23 { 25 super(); 26 27 _index = 0; 28 _commands = commandArray.concat(); 24 super( commandArray ); 29 25 } 30 26 31 27 32 public function push(com:ICommand):void 33 { 34 _commands.push(com); 35 } 28 36 29 37 30 as3/Commands/src/SerialCommand.as
r203 r231 4 4 5 5 /** 6 * 登録したコマンドを順番に実行し、全て実行したらCompleteイベントを発行する 6 * 登録された複数のコマンドを1つづつ順番に実行、終了させていきます。 7 * 最後のコマンドの終了時にEvent.COMPLETEを発行します。 7 8 * 8 * @usage 9 * SerialCommandインスタンスは1回だけの使用を前提とし、再利用は考慮されていません。 10 * 同じ処理を繰り返して行いたい場合には、処理の度に新しいSerialCommandインスタンスを作成してください。 9 11 * 10 * var coms : Array = [ 12 * @example 以下のコードは、hello と表示し、1秒後に world と表示します。 13 * <listing version="3.0"> 14 * var ar : Array = [ 11 15 * new Command("hello"), 12 16 * new WaitCommand(1000), 13 17 * new Command("world")]; 14 18 * 15 * var sCom : SerialCommand = new SerialCommand( coms ); 19 * var sCom : SerialCommand = new SerialCommand( ar ); 20 * sCom.addEventListener(Event.COMPLETE, _commandExecuteHandler); 16 21 * sCom.execute(); 22 * </listing> 17 23 * 18 24 */ 19 public class SerialCommand extends CommandBase25 public class SerialCommand extends BatchCommand 20 26 { 21 protected var _index:Number22 protected var _commands:Array23 27 /** 28 * @param comamndArray ICommandインターフェースを実装したコマンドの配列。 29 */ 24 30 public function SerialCommand( commandArray:Array ) 25 31 { 26 super(); 27 28 _index = 0; 29 _commands = commandArray.concat(); 30 } 31 32 public function push(com:ICommand):void 33 { 34 _commands.push(com); 32 super(commandArray); 35 33 } 36 34 … … 42 40 43 41 42 //内部的に次のコマンドを実行 44 43 protected function doNext():void 45 44 { … … 50 49 51 50 51 //子コマンドが終了したときのハンドラ 52 52 protected function doNextCompleteHandler( e:Event ):void 53 53 { 54 var c :ICommand = ICommand(e.target); 55 c.removeEventListener(Event.COMPLETE, doNextCompleteHandler); 56 54 e.target.removeEventListener(e.type, arguments.callee); 55 57 56 _index ++; 58 57 as3/Commands/src/ext/LoaderCommand.as
r211 r231 6 6 import flash.net.URLRequest; 7 7 import flash.display.Loader; 8 import flash.events.IOErrorEvent; 8 9 9 10 /* … … 14 15 request:URLRequest 15 16 urlScope:Object, urlProp:String 17 18 alternativeURL:String 代替イメージのURL 16 19 17 20 loader:Loader … … 33 36 loader = this.buildLoader(); 34 37 loader.contentLoaderInfo.addEventListener(Event.COMPLETE, _completeHandler, false, 0, true); 38 loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, _ioErrorHandler, false, 0, true); 35 39 36 40 loader.load(req); … … 42 46 { 43 47 loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, _completeHandler); 48 loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, _ioErrorHandler); 44 49 45 50 paramObj = null; 46 51 loader = null; 47 52 this.dispatchComplete(); 53 } 54 55 protected function _ioErrorHandler(e:Event):void 56 { 57 trace("irerror", paramObj.url); 58 if(paramObj.alternativeURL){ 59 loader.load(new URLRequest(paramObj.alternativeURL)); 60 }else{ 61 _completeHandler(e); 62 } 48 63 } 49 64

