チェンジセット 609

差分発生行の前後
無視リスト:
コミット日時:
2008/06/11 20:32:34 (4 年前)
コミッタ:
fladdict
ログメッセージ:

--

ファイル:

凡例:

変更無し
追加
削除
更新
コピー
移動
  • as3/Commands/src/commands/AsyncCommand.as

    r232 r609  
    55         
    66        /** 
     7         * 「任意の非同期処理を実行し、結果を待つ」コマンド. 
     8         *  
    79         * Executes async function call. E.G. Loader, URLLoader, etc... 
    810         * This Command register functions event dispacher and catch their event. 
  • as3/Commands/src/commands/BatchCommand.as

    r249 r609  
    44         
    55        /** 
    6          * ParallelCommand と SerialCommand のベースとなる抽象クラスです。 
    7          * このクラスが実際にインスタンス化されることはありません。 
     6         * ParallelCommand と SerialCommand のベースとなる抽象クラス. 
     7         *  
     8         * <p>このクラスが実際にインスタンス化されることはありません。</p> 
     9         *  
     10         * @see commands.ParallelCommand 
     11         * @see commands.SerialCommamd 
    812         */ 
    913        public class BatchCommand extends CommandBase 
     
    2327                /** 
    2428                 * ICommandインターフェースを実装したコマンドを処理に追加します。 
    25                  * @param com Command 
     29                 * @param com ICommandインターフェースを実装したコマンド。 
    2630                 */ 
    2731                public function push(com:ICommand):void 
     
    3236                 
    3337                /** 
    34                  * Commandインスタンスを作成し処理に追加するショートカット関数です。 
     38                 * Commandインスタンスを作成し処理に追加するショートカット関数。 
    3539                 */ 
    3640                public function pushCommand(thisObject:*, func:Function, params:Array=null):void 
    3741                { 
    38                         var c:Command = new Command(thisObject, func, params); 
    39                         push(c); 
     42                        push(new Command(thisObject, func, params)); 
    4043                } 
    4144                 
    4245                 
    4346                /** 
    44                  * WaitCommandインスタンスを作成し処理に追加するショートカット関数です。 
     47                 * WaitCommandインスタンスを作成し処理に追加するショートカット関数。 
    4548                 */ 
    4649                public function pushWait( delay:Number ):void 
    4750                { 
    48                         var c:WaitCommand = new WaitCommand(delay); 
    49                         push(c); 
     51                        push(new WaitCommand(delay)); 
    5052                } 
    5153                 
    5254                 
    5355                /** 
    54                  * SerialCommandインスタンスを作成し処理に追加するショートカット関数です。 
     56                 * SerialCommandインスタンスを作成し処理に追加するショートカット関数。 
    5557                 */ 
    5658                public function pushSerial( commands:Array = null ):void 
    5759                { 
    58                         var c:SerialCommand = new SerialCommand(commands); 
    59                         push(c); 
     60                        push(new SerialCommand(commands)); 
    6061                } 
    6162                 
    6263                 
    6364                /** 
    64                  * ParallelCommandインスタンスを作成し処理に追加するショートカット関数です。 
     65                 * ParallelCommandインスタンスを作成し処理に追加するショートカット関数。 
    6566                 */ 
    6667                public function pushParallel( commands:Array = null ):void 
    6768                { 
    68                         var c:ParallelCommand = new ParallelCommand(commands); 
    69                         push(c); 
     69                        push(new ParallelCommand(commands)); 
    7070                } 
    7171                 
    7272                public function pushAsync(thisObject:Object, func:Function, params:Array, eventDispatcher:EventDispatcher, eventType:String):void 
    7373                { 
    74                         var c:AsyncCommand = new AsyncCommand(thisObject, func, params, eventDispatcher, eventType); 
    75                         push(c); 
     74                        push(new AsyncCommand(thisObject, func, params, eventDispatcher, eventType)); 
    7675                } 
    7776                 
     77                /** 
     78                 * FrameWaitCommandインスタンスを作成し処理に追加するショートカット。 
     79                 */ 
    7880                public function pushFrameWait(frameNum:int):void 
    7981                { 
    80                         var c:FrameWaitCommand = new FrameWaitCommand(frameNum); 
    81                         push(c); 
     82                        push(new FrameWaitCommand(frameNum)); 
    8283                } 
    8384        } 
  • as3/Commands/src/commands/Command.as

    r317 r609  
    22{ 
    33        /** 
    4          * 関数execute()をコールすることで、あらかじめ登録しておいた処理を実行します。 
    5          * 処理の終了後にはEvent.COMPLETEが発行されます。 
     4         * 「任意の関数を実行する」コマンド. 
    65         *  
    7          * Commandクラスの現状の課題は、インスタンスの作成時の段階で、 
    8          * 関数およびパラメーターが存在していなければならないことです。 
    9          * 将来的には関数、パラメーターに対して遅延評価を行うことのできる仕組みを実装する予定です。 
     6         * <p>Commandクラスを用いることで、「関数の呼び出し」という行為を変数としてやりとりするが可能となります。</p> 
    107         *  
    11          * @example 以下はCommandクラスの基本的な使い方です。 
     8         * @example 以下はCommandクラスの基本的な使い方です。この例では"Hello Command"という文字列を表示するCommandを作成し、実行しています。 
    129         * <listing version="3.0"> 
    13          * var command:Command = new Command(null, trace, [""]); 
     10         * var command:Command = new Command(null, trace, ["Hello Command"]); 
    1411         * command.execute(); 
    15          * </listing> 
     12         *  
     13         * //Outputs 
     14         * //Hello Command</listing> 
    1615         *  
    1716         */ 
    1817        public class Command extends CommandBase 
    1918        { 
    20                 protected var _thisObject : Object 
     19                //このthisObjectはクロージャのthisスコープをコントロールする為に、一応のこしておく。 
     20                protected var _thisObject : Object; 
    2121                protected var _function : Function; 
    2222                protected var _params : Array; 
     
    2525                 * 関数execute()実行時に行いたい処理を登録します。 
    2626                 *  
    27                  * @param thisObject Thisとして使用されるスコープです。AS3では指定する必要はありません。AS2との互換性の為に存在しています。 
     27                 * @param thisObject Thisとして使用されるスコープです。基本的にnullで問題ありません。クロージャおよびAS2との互換性の為に存在しています。 
    2828                 * @param func:Function 登録したい関数の参照。 
    2929                 * @param params:Array 関数実行時に渡されるパラメーター 
     
    3232                { 
    3333                        super(); 
    34                         _thisObject = thisObject 
    35                         _function = func 
    36                         _params = params 
     34                        _thisObject = thisObject; 
     35                        _function = func; 
     36                        _params = params; 
    3737                } 
    3838                 
     
    4646                override public function execute():void 
    4747                { 
    48                         if(_params){ 
    49                                 _function.apply(_thisObject, _params);  
    50                         }else{ 
    51                                 _function.apply(_thisObject); 
    52                         } 
    53                          
     48                        _function.apply(_thisObject, _params);  
    5449                        this.dispatchComplete(); 
    5550                } 
  • as3/Commands/src/commands/CommandBase.as

    r232 r609  
    55         
    66        /** 
    7          * commandsパッケージで使用されるコマンドのルートとなる抽象クラス。 
    8          * 独自のコマンドクラスを作成する場合には、基本的にこのクラスを継承してください。 
     7         * 全てのコマンドの基底クラス. 
     8         *  
     9         * <p>このクラスが直接使われることはありません。独自のコマンドを作成する場合には、このクラスを継承してください。</p> 
    910         */ 
    1011        public class CommandBase extends EventDispatcher implements ICommand 
    1112        { 
    1213                /** 
    13                  * テンプレート関数。 
     14                 * コマンドとして定義された処理を実行します. 
    1415                 *  
    15                  * この関数をオーバーライドして実行したい処理を書きます。 
    16                  * 同期処理、非同期処理にかかわらず、処理の終了時には関数dispatchComplete()をコールしてください。 
     16                 * <p>この関数はテンプレート関数です。実際の実装はサブクラスで行われます。</p> 
     17                 * <p>サブクラスの実装ではexecuteによって行われる全ての処理の終了時に、関数dispatchComplete()を呼び出してください。</p> 
    1718                 */ 
    18                 public function execute():void{} 
     19                public function execute():void 
     20                { 
     21                        //ここに実行したい処理を書く 
     22                        dispatchComplete(); 
     23                } 
    1924                 
    2025                 
    2126                /** 
    22                  * テンプレート関数。 
    23                  *  
    24                  * この関数は将来の拡張の為に予約されています。 
     27                 * この関数は将来の拡張の為に予約されています。. 
    2528                 */ 
    2629                public function cancel():void{} 
     
    2831                 
    2932                /** 
    30                  * コマンドの終了を通知する為に、Event.COMPLETEを発行します。 
     33                 * コマンドの終了を通知する為に、Event.COMPLETEを発行します. 
     34                 *  
     35                 * <p>CommandBaseのサブクラスでは、execute()で実行する処理の終了時には、 
     36                 * 明示的にこの関数を呼び出してください</p> 
    3137                 */ 
    3238                protected function dispatchComplete():void 
  • as3/Commands/src/commands/CommandContainer.as

    r317 r609  
    55         
    66        /** 
    7          * 変数内にCommandインスタンスを残して参照地獄にならないように、 
    8          * 実行中のICommandを実装したクラスを一時的にホールドする為のクラスです。 
    9          * 実行終了後にICommandインスタンスへの参照は開放されます。 
     7         * 実行中の非同期コマンドがガベージコレクトされないよう、参照を保持するクラス. 
    108         *  
    11          * @example 
     9         * SerialCommand, ParallelCommand, AsyncCommandなど非同期のコマンドが、実行中にガベージコレクションされるのを防ぐのに用いられます。 
     10         * 実行終了後、CommandContainerに格納されたICommandインスタンスへの参照は開放されます。 
     11         *  
     12         * @example 以下の例ではSerialCommandを実行し、その終了までSerialCommandの参照を保持します。 
    1213         * <listing version="3.0"> 
    1314         * var serialCommand = new SerialCommand([ 
    1415         *   new Command(null, trace, ["test"]); 
    15          *   new WaitCommand(1000); 
     16         *   new WaitCommand(10000); 
    1617         *   new Command(null, trace, ["test"]); 
    1718         * ]) 
     
    2223        public class CommandContainer 
    2324        { 
    24                 protected static var commandDict:Dictionary 
     25                protected static var _commandDict:Dictionary 
    2526                protected static var _numCommands:int = 0; 
    2627                 
    27                 public static function execute(command:ICommand):ICommand 
     28                /** 
     29                 * 引数として渡したICommandを実行し、処理が終了するまで参照を保持します。 
     30                 *  
     31                 * コマンドの終了時、CommandContainer内に保持された参照は破棄されます。 
     32                 */ 
     33                public static function execute(command:ICommand):void 
    2834                { 
    29                         if(commandDict==null) 
    30                                 commandDict = new Dictionary(); 
     35                        if(_commandDict==null) 
     36                                _commandDict = new Dictionary(); 
    3137                                 
    32                         if(commandDict[command]){ 
     38                        if(_commandDict[command]){ 
    3339                                throw new Error("CommandContainer.execute() this command is alrealdy registerd"); 
    3440                        } 
    3541                         
    36                         commandDict[command] = command; 
     42                        _commandDict[command] = command; 
    3743                        _numCommands++; 
    3844                         
    3945                        command.addEventListener(Event.COMPLETE, executeHandler); 
    4046                        command.execute(); 
    41                          
    42                         return command; 
    4347                } 
    4448                 
     49                 
     50                //デバッグ用、現在実行中のコマンドの数を返す。 
    4551                public static function get numCommands():int 
    4652                { 
     
    4854                } 
    4955                 
     56                 
     57                //デバッグ用、現在実行中のコマンドをダンプする。 
    5058                public static function dump():void 
    5159                { 
    52                         for (var prop:* in commandDict){ 
    53                                 trace(commandDict[prop]); 
     60                        for (var prop:* in _commandDict){ 
     61                                trace(_commandDict[prop]); 
    5462                        } 
    5563                } 
    5664                 
     65                 
     66                /* 
     67                        コマンドの終了のハンドリング。 
     68                        終了したコマンドのリスナ解除と、参照の廃棄を行う。 
     69                */ 
    5770                protected static function executeHandler(e:Event):void 
    5871                { 
     
    6174                        _numCommands--; 
    6275                         
    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]; 
    6879                } 
    6980        } 
  • as3/Commands/src/commands/FrameWaitCommand.as

    r305 r609  
    66         
    77        /** 
    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 
    1015         */ 
    1116        public class FrameWaitCommand extends CommandBase 
     
    2126                } 
    2227                 
     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                 
    2340                override public function execute():void 
    2441                { 
    2542                        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."); 
    2744                        enterFrameBeacon.addEventListener(Event.ENTER_FRAME, _enterFrameHandler, false, 0, true); 
    2845                } 
  • as3/Commands/src/commands/ICommand.as

    r232 r609  
    33         
    44        /** 
    5          * commandsライブラリで使用される共通インターフェース 
     5         * commandsライブラリで使用される共通インターフェース. 
    66         */ 
    77        public interface ICommand 
     
    2626                 */ 
    2727                function execute():void 
     28                 
     29                function cancel():void 
    2830        } 
    2931} 
  • as3/Commands/src/commands/ParallelCommand.as

    r249 r609  
    44         
    55        /** 
    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         * 「全ての子コマンドを同時に実行し、その全ての終了を待つ」コマンド. 
    97         *  
     8         * <p>登録された複数のコマンドを全て同時に実行し、その全てのコマンドが終了するとEvent.COMPLETEが発行されます。 
     9         * 複数のデータが全てロードされるのを待つ時等に用いられます</p> 
     10         *  
     11         * @example 以下の例では、「文字の表示」「1秒待ち」「文字を表示」を同時に実行し、全てが終了した時点(つまり1秒後)にEvent.COMPLETEを発行します。" 
     12         * <listing version="3.0"> 
    1013         * var coms : Array = [ 
    1114         *              new Command("hello"), 
     
    1518         * var pCom : ParallelCommand = new ParallelCommand( coms ); 
    1619         * pCom.addEventListener(Event.COMPLETE, _commandCompleteHandler); 
    17          * pCom.execute(); 
    1820         *  
     21         * CommandContainer.execute( pCom);</listing> 
     22         *  
     23         * @see commands.SerialCommand 
     24         * @see commands.CommandContainer 
    1925         */ 
    2026        public class ParallelCommand extends BatchCommand 
     
    2430                        super( commandArray ); 
    2531                } 
    26                  
    27                  
    28                  
    2932                 
    3033                 
  • as3/Commands/src/commands/SerialCommand.as

    r249 r609  
    44         
    55        /** 
    6          * 登録された複数のコマンドを1つづつ順番に実行、終了させていきます。 
    7          * 最後のコマンドの終了時にEvent.COMPLETEを発行します。 
     6         * 「全ての子コマンドを1つづつ実行・終了する」コマンド. 
    87         *  
    9          * SerialCommandインスタンスは1回だけの使用を前提とし、再利用は考慮されていません。 
    10          * 同じ処理を繰り返して行いたい場合には、処理の度に新しいSerialCommandインスタンスを作成してください。 
     8         * <p>登録された複数のコマンドを1つづつ順番に実行、終了させていきます。 
     9         * 最後のコマンドの終了時にEvent.COMPLETEを発行します。</p> 
     10         *  
     11         * <p>SerialCommandインスタンスは1回だけの使用を前提とし、再利用は考慮されていません。 
     12         * 同じ処理を繰り返して行いたい場合には、処理の度に新しいSerialCommandインスタンスを作成してください。</p> 
    1113         *  
    1214         * @example 以下のコードは、hello と表示し、1秒後に world と表示します。 
     
    1921         * var sCom : SerialCommand = new SerialCommand( ar ); 
    2022         * sCom.addEventListener(Event.COMPLETE, _commandExecuteHandler); 
    21          * sCom.execute(); 
     23         *  
     24         * //ガベージコレクトされないよう、CommandContainerを用いて実行する。 
     25         * CommandContainer.execute(sCom); 
    2226         * </listing> 
    2327         *  
     28         * @see commands.CommandContainer 
    2429         */ 
    2530        public class SerialCommand extends BatchCommand 
  • as3/Commands/src/commands/WaitCommand.as

    r250 r609  
    55         
    66        /** 
    7          * Dispatches Event.COMPLETE event after certain delay. 
    8          * Used for taking a break between multiple commands. 
     7         * 「指定したミリ秒待機する」コマンド. 
    98         *  
    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 
    1330         */ 
    1431        public class WaitCommand extends CommandBase 
     
    1835                 
    1936                /** 
    20                  * dispatches Event.COMPLETE event after certain delay. 
    21                  * @param millisecond duration for delay 
     37                 * 「指定したミリ秒だけ待つ」コマンド。 
     38                 *  
     39                 * @param 待ち時間のミリ秒。 
    2240                 */ 
    2341                public function WaitCommand( delay:Number = 1000) 
  • as3/Commands/src/commands/ext/ProcessCommand.as

    r245 r609  
    77 
    88        /** 
    9          * 指定の関数が true を返すまで、定期的にコールするコマンド。 
    10          * スタックの消化や擬似スレッド等を行いたい場合に使う 
     9         * 指定の関数が true を返すまで、値をチェックするコールするコマンド。 
     10         * 何かの処理の処理や、条件が整うまでスタックの消化や擬似スレッド等を行いたい場合に使う 
    1111         */ 
    1212        public class ProcessCommand extends CommandBase 
  • as3/Commands/src/commands/ext/URLLoaderCommand.as

    r317 r609  
    11package commands.ext 
    22{ 
    3         import commands.Command; 
     3        import commands.CommandBase; 
     4         
     5        import flash.events.Event; 
     6        import flash.events.IOErrorEvent; 
    47        import flash.net.URLLoader; 
     8        import flash.net.URLLoaderDataFormat; 
    59        import flash.net.URLRequest; 
    6         import flash.net.URLLoaderDataFormat; 
    7         import flash.events.Event; 
    8         import commands.CommandBase; 
    9         import flash.events.IOErrorEvent; 
    1010        import flash.net.URLVariables; 
    1111