チェンジセット 349: as2/Commands
- コミット日時:
- 2008/04/27 20:47:20 (4 年前)
- ファイル:
-
- as2/Commands/src/jp/cellfusion/commands/Command.as (更新) (2 diffs)
- as2/Commands/src/jp/cellfusion/commands/EnterFrameCommand.as (更新) (7 diffs)
- as2/Commands/tests/UnitTest.as (追加)
- as2/Commands/tests/jp/cellfusion/commands/ASyncCommandTest.as (移動) (as2/Commands/tests/jp/cellfusion/commands/SendAndLoadCommandTest.as から 移動) (1 diff)
- as2/Commands/tests/jp/cellfusion/commands/AllTests.as (更新) (2 diffs)
- as2/Commands/tests/jp/cellfusion/commands/CommandTest.as (更新) (1 diff)
- as2/Commands/tests/jp/cellfusion/commands/EnterFrameCommandTest.as (更新) (2 diffs)
- as2/Commands/tests/jp/cellfusion/commands/SerialCommandTest.as (移動) (as2/Commands/tests/jp/cellfusion/commands/SequenceCommandTest.as から 移動) (1 diff)
- as2/Commands/tests/jp/cellfusion/commands/TimerCommandTest.as (更新) (2 diffs)
- as2/Commands/tests/unitTest.fla (移動) (as2/Commands/unitTest.fla から 移動)
- as2/Commands/tests/unitTest.swf (移動) (as2/Commands/unitTest.swf から 移動)
凡例:
- 変更無し
- 追加
- 削除
- 更新
- コピー
- 移動
as2/Commands/src/jp/cellfusion/commands/Command.as
r347 r349 23 23 private var _args:Array; 24 24 private var _eventDispatcher:EventDispatcher; 25 26 private var _result:Object;27 public function get result():Object { return _result; }28 25 29 26 /** … … 60 57 func = typeof(_funcRef) == "string" ? _thisObj[_funcRef] : _funcRef; 61 58 } 62 63 if (arguments.length > 0) _result = func.apply(_thisObj, arguments); 64 else _result = func.apply(_thisObj, _args); 59 func.apply(_thisObj, _args); 65 60 66 61 dispatchEvent(new CommandEvent(CommandEvent.COMMAND_PROGRESS, this)); as2/Commands/src/jp/cellfusion/commands/EnterFrameCommand.as
r348 r349 55 55 * 実行 56 56 */ 57 public function execute(): Boolean57 public function execute():Void 58 58 { 59 59 reset(); 60 60 MovieClip.addListener(this); 61 return true;62 61 } 63 62 … … 65 64 * 中止 66 65 */ 67 public function abort(): Boolean66 public function abort():Void 68 67 { 69 68 MovieClip.removeListener(this); 70 return true;71 69 } 72 70 … … 74 72 * 再会 75 73 */ 76 public function resume(): Boolean74 public function resume():Void 77 75 { 78 76 MovieClip.addListener(this); 79 return true;80 77 } 81 78 … … 83 80 * リセット 84 81 */ 85 public function reset() 82 public function reset():Void 86 83 { 87 84 _currentCount = 0; 88 85 _currentDelay = 0; 89 MovieClip.removeListener(this);90 86 } 91 87 … … 103 99 } 104 100 105 private function onEnterFrame() 101 private function onEnterFrame():Void 106 102 { 107 103 _currentDelay++; … … 109 105 _currentDelay = 0; 110 106 111 super.execute(); 107 var func:Function 108 if (_thisObj == null) { 109 func = typeof(_funcRef) == "string" ? _global[_funcRef] : _funcRef; 110 } else { 111 func = typeof(_funcRef) == "string" ? _thisObj[_funcRef] : _funcRef; 112 } 113 func.apply(_thisObj, arguments); 112 114 113 115 _currentCount++; … … 115 117 // 繰り返し回数が 0 の場合は終了しない 116 118 if (_currentCount == _repeatCount && _repeatCount != 0) { 117 _commandComplete();119 commandComplete(); 118 120 } 119 121 } 120 122 } 121 123 122 private function _commandComplete()124 private function commandComplete():Void 123 125 { 124 reset();126 MovieClip.removeListener(this); 125 127 126 128 dispatchEvent(new CommandEvent(CommandEvent.COMMAND_COMPLETE, this)); as2/Commands/tests/jp/cellfusion/commands/ASyncCommandTest.as
r323 r349 3 3 * @author cellfusion 4 4 */ 5 class jp.cellfusion.commands. SendAndLoadCommandTest extends TestCase5 class jp.cellfusion.commands.ASyncCommandTest extends TestCase 6 6 { 7 7 } as2/Commands/tests/jp/cellfusion/commands/AllTests.as
r323 r349 4 4 import jp.cellfusion.commands.CommandTest; 5 5 import jp.cellfusion.commands.EnterFrameCommandTest; 6 import jp.cellfusion.commands.LoaderCommandTest;7 import jp.cellfusion.commands.MacroCommandTest;8 import jp.cellfusion.commands.SendAndLoadCommandTest;9 import jp.cellfusion.commands.SequenceCommandTest;10 6 import jp.cellfusion.commands.TimerCommandTest; 11 import jp.cellfusion.commands.TweenCommandTest;12 import jp.cellfusion.commands.events.CommandEventTest;13 7 /** 14 8 * @author cellfusion … … 20 14 var suite:TestSuite = new TestSuite(null, "Commands Tests"); 21 15 suite.addTestSuite(CommandTest); 22 // suite.addTestSuite(EnterFrameCommandTest); 16 suite.addTestSuite(EnterFrameCommandTest); 17 suite.addTestSuite(TimerCommandTest); 23 18 // suite.addTestSuite(LoaderCommandTest); 24 19 // suite.addTestSuite(MacroCommandTest); 25 // suite.addTestSuite(SendAndLoadCommandTest); 26 // suite.addTestSuite(SequenceCommandTest); 27 // suite.addTestSuite(TimerCommandTest); 20 // suite.addTestSuite(ASyncCommandTest); 21 // suite.addTestSuite(SerialCommandTest); 28 22 // suite.addTestSuite(TweenCommandTest); 29 23 // suite.addTestSuite(CommandEventTest); as2/Commands/tests/jp/cellfusion/commands/CommandTest.as
r323 r349 12 12 var cmd:Command = new Command(this, hoge, ["hoge", 33]); 13 13 cmd.execute(); 14 14 } 15 16 public function testStringComman():Void 17 { 15 18 // 関数名を渡す 16 19 var strCmd:Command = new Command(this, "fuga", ["hoge", 33]); as2/Commands/tests/jp/cellfusion/commands/EnterFrameCommandTest.as
r323 r349 1 import org.libspark.asunit.framework.TestCase; 1 import jp.cellfusion.commands.events.CommandEvent; 2 3 import mx.utils.Delegate; 4 5 import org.libspark.asunit.framework.TestCase; 2 6 import jp.cellfusion.commands.EnterFrameCommand; 3 7 /** … … 7 11 { 8 12 private var _count:Number; 9 13 private var _completeDelegate:Function; 14 10 15 public function testCommand():Void 11 16 { 17 _completeDelegate = Delegate.create(this, completeHandler); 18 19 _count = 0; 20 21 var cmd:EnterFrameCommand = new EnterFrameCommand(this, countUp, [], 1, 5); 22 23 cmd.addEventListener(CommandEvent.COMMAND_COMPLETE, _completeDelegate); 24 25 cmd.execute(); 12 26 } 27 28 private function countUp():Void 29 { 30 _count++; 31 } 32 33 private function completeHandler(e:CommandEvent):Void 34 { 35 assertEquals(_count, 5); 36 } 37 13 38 } as2/Commands/tests/jp/cellfusion/commands/SerialCommandTest.as
r323 r349 3 3 * @author cellfusion 4 4 */ 5 class jp.cellfusion.commands.Se quenceCommandTest extends TestCase5 class jp.cellfusion.commands.SerialCommandTest extends TestCase 6 6 { 7 7 } as2/Commands/tests/jp/cellfusion/commands/TimerCommandTest.as
r323 r349 1 import org.libspark.asunit.framework.TestCase; 1 import mx.utils.Delegate; 2 3 import org.libspark.asunit.framework.TestCase; 2 4 3 5 import jp.cellfusion.commands.TimerCommand; 6 import jp.cellfusion.commands.events.CommandEvent; 4 7 /** 5 8 * @author cellfusion … … 8 11 { 9 12 private var _count:Number; 10 11 private function testCommand():Void 13 private var _commandCompleteDelegate:Function; 14 15 private function testTimerCommand():Void 12 16 { 17 _commandCompleteDelegate = Delegate.create(this, commandCompleteHandler); 13 18 _count = 0; 14 19 15 var tmrCmd:TimerCommand = new TimerCommand(this, progress, ["hoge", 5], 500, 5); 20 var tmrCmd:TimerCommand = new TimerCommand(this, countUp, ["hoge", 5], 500, 5); 21 tmrCmd.addEventListener(CommandEvent.COMMAND_COMPLETE, _commandCompleteDelegate); 16 22 tmrCmd.execute(); 17 23 } 18 24 19 private function progress(str:String, num:Number):Void25 private function commandCompleteHandler(e:CommandEvent):Void 20 26 { 27 assertEquals(_count, 5); 28 } 29 30 private function countUp(str:String, num:Number):Void 31 { 32 _count++; 21 33 34 assertEquals(str, "hoge", "param test"); 35 assertEquals(num, 5, "param test"); 22 36 } 23 37 }

