FrontControllerクラス解説
まずはソース
import com.iterationtwo.cairngorm.control.*; import com.iterationtwo.cairngorm.commands.*; import mx.events.*; class com.iterationtwo.cairngorm.control.FrontController { public function FrontController() { commands = new Array(); } private function handleEvent( event:Event ) : Void { executeCommand( event ); } private function executeCommand( event : Event ) : Void { var command:Command = getCommand( event.type ); command.execute( event ); } public function addCommand( commandName:String, commandRef:Command ) : Void { commands[ commandName ] = commandRef; EventBroadcaster.getInstance().addEventListener( commandName, this ); } private function getCommand ( commandName ) : Command { var command:Command = commands[ commandName ]; if ( command == null ) trace( "Command not found for " + commandName ); return command; } private var commands:Array; }
そして解説
FrontControlloerは継承して使う。以下、例
class LoginController extends com.iterationtwo.cairngorm.control.FrontController { public function LoginController() { initialiseCommands(); } public function initialiseCommands() : Void { addCommand( "login", new LoginCommand() ); addCommand( "logout", new LogoutCommand() ); } }