{"id":1659,"date":"2013-06-23T11:18:11","date_gmt":"2013-06-23T02:18:11","guid":{"rendered":"http:\/\/www.whoocus.com\/blog\/?p=1659"},"modified":"2013-06-23T11:38:03","modified_gmt":"2013-06-23T02:38:03","slug":"puremvc-for-as3","status":"publish","type":"post","link":"https:\/\/www.blowfish.co.jp\/?p=1659","title":{"rendered":"PureMVC for AS3"},"content":{"rendered":"<p>\u5143\u3005Flex\u30a8\u30f3\u30b8\u30cb\u30a2\u3060\u3063\u305f\u306e\u3067\u3001PureMVC\u306b\u306f\u4ee5\u524d\u304b\u3089\u8208\u5473\u304c\u3042\u3063\u305f\u306e\u3060\u304c\u3001\u4ee5\u524d\u306f\u6642\u9593\u306e\u554f\u984c\u304b\u3089\u8ae6\u3081\u3066\u3044\u305f\u3002PureMVC\u306e\u672c\u5bb6\u30b5\u30a4\u30c8\u306e\u60c5\u5831\u3082\u4e2d\u3005\u96e3\u89e3\u3067\u3001\u6b63\u76f4MVC\u306e\u69cb\u9020\u306f\u7406\u89e3\u3067\u304d\u308b\u306e\u3060\u304c\u3001\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3068\u3057\u3066\u306e\u5b9a\u756a\u306e\u8a18\u8ff0\u304c\u3088\u304f\u308f\u304b\u3089\u305a\u3001\u5177\u4f53\u7684\u306b\u8a18\u8ff0\u3067\u304b\u306a\u308a\u8ff7\u3063\u3066\u3044\u305f\u3002<\/p>\n<p>\u305d\u3053\u3067\u6539\u3081\u3066\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u6574\u7406\u3057\u3066\u307f\u305f\u3002\u4f46\u3057\u3001\u79c1\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u8a18\u8ff0\u304c\u5408\u3063\u3066\u3044\u308b\u3068\u306f\u601d\u308f\u306a\u3044\u3067\u307b\u3057\u3044\u3002<\/p>\n<p><strong>Main.mxml<\/strong><br \/>\n[java]<br \/>\n  &lt;s:WindowedApplication applicationComplete=&quot;facade.startup(this)&quot;&gt;<br \/>\n  &lt;fx:Script&gt;<br \/>\n  &lt;![CDATA[<br \/>\n    import com.whoocus.flex.ApplicationFacade;<br \/>\n    import mx.events.FlexEvent;<br \/>\n    \/\/ Initialize the PureMVC Facade<br \/>\n    private var facade:ApplicationFacade = ApplicationFacade.getInstance();<br \/>\n  ]]&gt;<br \/>\n  &lt;\/fx:Script&gt;<br \/>\n[\/java]<\/p>\n<p>\u7c21\u5358\u306b\u8a00\u3046\u3068\u3001ApplicationFacade\u306e\u30b7\u30f3\u30b0\u30eb\u30c8\u30f3\u30af\u30e9\u30b9\u3092\u547c\u3073\u51fa\u3059\u3002<br \/>\n\u305d\u306efacade\u30af\u30e9\u30b9\u306estartup\u30e1\u30bd\u30c3\u30c9\u3067\u3067\u30a2\u30d7\u30ea\u3092Main\u3092\u767b\u9332\u3057\u3066\u521d\u671f\u5316\u51e6\u7406\u304c\u59cb\u307e\u308b\u3002<\/p>\n<p><strong>ApplicationFacade.as<\/strong><br \/>\n[java]<br \/>\npublic class ApplicationFacade extends Facade<br \/>\n{<br \/>\n  \/**<br \/>\n  * \u30b7\u30f3\u30b0\u30eb\u30c8\u30f3\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u751f\u6210\u53d6\u5f97\u30e1\u30bd\u30c3\u30c9<br \/>\n  *\/<br \/>\n  public static function getInstance( ) : ApplicationFacade<br \/>\n  {<br \/>\n    if ( instance == null ) instance = new ApplicationFacade();<br \/>\n      return instance as ApplicationFacade;<br \/>\n    }<br \/>\n  \/**<br \/>\n   * PureMVC \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u30b9\u30bf\u30fc\u30c8\u30a2\u30c3\u30d7\u30e1\u30bd\u30c3\u30c9<br \/>\n   *\/<br \/>\n  public function startup( app:Main ):void<br \/>\n  {<br \/>\n    registerCommand( AppConstants.STARTUP, StartupCommand);<br \/>\n    sendNotification( AppConstants.STARTUP, app );<br \/>\n  }<br \/>\n}<br \/>\n[\/java]<\/p>\n<p>startup\u30e1\u30bd\u30c3\u30c9\u306eregisterCommand\u3067\u3001\u30b3\u30de\u30f3\u30c9\u30af\u30e9\u30b9\u3092\u767b\u9332\u3057sendoNotification\u901a\u77e5\u3092\u9001\u4fe1\u3059\u308b\u3002<\/p>\n<p><b>StartupCommand.as<\/b><br \/>\n[java]<br \/>\npublic class StartupCommand extends MacroCommand<br \/>\n{<br \/>\n  override protected function initializeMacroCommand():void<br \/>\n  {<br \/>\n    addSubCommand(PrepareControllerCommand);<br \/>\n    addSubCommand(PrepareModelCommand);<br \/>\n    addSubCommand(PrepareViewCommand);<br \/>\n  }<br \/>\n}<br \/>\n[\/java]<br \/>\nStartupCommand\u5185\u3067\u306f\u3001\u3068\u308a\u3042\u3048\u305acontroller\/model\/view \u306e\u5358\u4f4d\u3067\u767b\u9332\u3059\u308b\u30b3\u30de\u30f3\u30c9\u3092\u5c0f\u5206\u3051\u3057\u3066\u3044\u308b\u3002<\/p>\n<p><b>PrepareControllerCommand.as<\/b><br \/>\n[java]<br \/>\npublic class PrepareControllerCommand extends SimpleCommand<br \/>\n{<br \/>\n  \/**<br \/>\n   * Command\u767b\u9332\u51e6\u7406<br \/>\n   *\/<br \/>\n  override public function execute(notification:INotification):void<br \/>\n  {<br \/>\n    \/\/Command\u767b\u9332\u51e6\u7406<br \/>\n    facade.registerCommand(AppConstants.HELLO, HelloCommand);<br \/>\n  }<br \/>\n}<br \/>\n[\/java]<\/p>\n<p><b>PrepareControllerCommand.as<\/b><br \/>\n[java]<br \/>\npublic class PrepareModelCommand extends SimpleCommand<br \/>\n{<br \/>\n  \/**<br \/>\n   * Proxy\u767b\u9332\u51e6\u7406<br \/>\n   *\/<br \/>\n  override public function execute(notification:INotification):void<br \/>\n  {<br \/>\n    \/\/Proxy\u767b\u9332\u51e6\u7406<br \/>\n    facade.registerProxy(helloProxy);<br \/>\n  }<br \/>\n}<br \/>\n[\/java]<\/p>\n<p><b>PrepareViewCommand.as<\/b><br \/>\n[java]<br \/>\npublic class PrepareControllerCommand extends SimpleCommand<br \/>\n{<br \/>\n  \/**<br \/>\n   * Mediator\u767b\u9332\u51e6\u7406<br \/>\n   *\/<br \/>\n  override public function execute(notification:INotification):void<br \/>\n  {<br \/>\n    \/\/Mediator\u767b\u9332\u51e6\u7406<br \/>\n    facade.registerMediator(new ApplicationMediator(app));<br \/>\n    facade.registerMediator(new HelloMediator(app.greeting));<br \/>\n  }<br \/>\n}<br \/>\n[\/java]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5143\u3005Flex\u30a8\u30f3\u30b8\u30cb\u30a2\u3060\u3063\u305f\u306e\u3067\u3001PureMVC\u306b\u306f\u4ee5\u524d\u304b\u3089\u8208\u5473\u304c\u3042\u3063\u305f\u306e\u3060\u304c\u3001\u4ee5\u524d\u306f\u6642\u9593\u306e\u554f\u984c\u304b\u3089\u8ae6\u3081\u3066\u3044\u305f\u3002PureMVC\u306e\u672c\u5bb6\u30b5\u30a4\u30c8\u306e\u60c5\u5831\u3082\u4e2d\u3005\u96e3\u89e3\u3067\u3001\u6b63\u76f4MVC\u306e\u69cb\u9020\u306f\u7406\u89e3\u3067\u304d\u308b\u306e\u3060\u304c\u3001\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3068\u3057\u3066\u306e\u5b9a\u756a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"saved_in_kubio":false,"footnotes":""},"categories":[8,39,4],"tags":[56],"class_list":["post-1659","post","type-post","status-publish","format-standard","hentry","category-flex","category-puremvc","category-tech","tag-puremvc"],"_links":{"self":[{"href":"https:\/\/www.blowfish.co.jp\/index.php?rest_route=\/wp\/v2\/posts\/1659","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.blowfish.co.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.blowfish.co.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.blowfish.co.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.blowfish.co.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1659"}],"version-history":[{"count":10,"href":"https:\/\/www.blowfish.co.jp\/index.php?rest_route=\/wp\/v2\/posts\/1659\/revisions"}],"predecessor-version":[{"id":1669,"href":"https:\/\/www.blowfish.co.jp\/index.php?rest_route=\/wp\/v2\/posts\/1659\/revisions\/1669"}],"wp:attachment":[{"href":"https:\/\/www.blowfish.co.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1659"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.blowfish.co.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1659"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.blowfish.co.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1659"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}