Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: MultiCore + AIR + resize window  (Read 8578 times)
Ondina
Sr. Member
****
Posts: 86


View Profile Email
« on: February 27, 2009, 04:23:59 »

I'm 7 days old (puremvc time).
So I still know/remember what newbies go through when trying to use this (or other new) framework in their projects and I thought that before leaving (some day..) the puremvc-kindergarten I could tell the newbies coming after me how  to play with the coolest puremvc-toys.

I took the CodePeek example and simplified it and made it run under the MultiCore version.
Maybe there is such an example already, but I didn't find it even after in depth search. If the post isn't useful or if it is redundant you (moderators) can delete it.
I don't know if everything is correct in my code below but it works.

MultiAir
libs
   PureMVC_AS3_MultiCore_1_0_5.swc

   Utility_AS3_MultiCore_AIR_DesktopCitizen_1_2_1.swc
   (This utility provides the ability for PureMVC-based AIR applications remember their window size, position and maximized state each time it is launched. )

src
      org.controller
      StartupCommand.as
org.view
   components
      AppControlBar.mxml
   AppControlBarMediator.as
   ApplicationMediator.as
ApplicationFacade.as

   MultiAir.mxml
------------------------------------
MultiAir.mxml (main)

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
   xmlns:view="org.view.components.*"   
   applicationComplete="facade.startup(this)"
   layout="absolute"
   >
   <mx:Script>
      <![CDATA[
         import org.ApplicationFacade;
         // App name
             public static const NAME:String = "MultiAir";
         // Initialize the PureMVC multicore-apparatus
             private var facade:ApplicationFacade = ApplicationFacade.getInstance( NAME );
             [Bindable] public var showControls:Boolean = false;    
      ]]>
   </mx:Script>
   <!-- The Application Control Bar -->
   <view:AppControlBar id="controlBar"/>
   <mx:TextArea x="10" y="10"  width="250" height="250"/>
</mx:WindowedApplication>

------------------------------------
ApplicationFacade.as

package org
{
   import org.puremvc.as3.multicore.utilities.air.desktopcitizen.DesktopCitizenConstants;
   import org.puremvc.as3.multicore.utilities.air.desktopcitizen.controller.WindowOpenCommand;
   
   import org.puremvc.as3.multicore.patterns.facade.Facade;
      
   import org.controller.StartupCommand;
   import org.controller.ShutdownCommand;

   public class ApplicationFacade extends Facade
   {
      // Notification name constants
      public static const STARTUP:String            = "startup";
      
      public function ApplicationFacade( key:String )
       {
          super(key);   
       }
       
        public static function getInstance( key:String ) : ApplicationFacade
        {
            if ( instanceMap[ key ] == null ) instanceMap[ key ]  = new ApplicationFacade( key );
            return instanceMap[ key ] as ApplicationFacade;
        }
   
      public function startup ( app:MultiAir ) : void
      {
         sendNotification( STARTUP, app );
      }
         
      override protected function initializeController () : void
      {
         super.initializeController();
         registerCommand( STARTUP, StartupCommand );
      }   
   }
}
--------------------------------------------
StartupCommand.as

package org.controller
{
   import org.puremvc.as3.multicore.interfaces.*;
   import org.puremvc.as3.multicore.patterns.command.*;

   import org.view.*;

   import org.puremvc.as3.multicore.utilities.air.desktopcitizen.DesktopCitizenConstants;
   
   /**
    * Create and register <code>Proxy</code>s with the <code>Model</code>.
    */
   public class StartupCommand extends SimpleCommand
   {
      override public function execute( note:INotification ) :void   {
         
         var app:MultiAir = note.getBody() as MultiAir;
         
         facade.registerMediator( new ApplicationMediator( app ) );
         sendNotification( DesktopCitizenConstants.WINDOW_OPEN, app.stage );
      }
   }
}
-------------------------------------
ApplicationMediator.as

package org.view
{
   import flash.events.Event;
   
   import org.puremvc.as3.multicore.interfaces.*;
   import org.puremvc.as3.multicore.patterns.mediator.*;

   import org.ApplicationFacade;
   import org.model.*;
   
   import org.puremvc.as3.multicore.utilities.air.desktopcitizen.DesktopCitizenConstants;

   public class ApplicationMediator extends Mediator implements IMediator
   {
      // Cannonical name of the Mediator
      public static const NAME:String = 'ApplicationMediator';
      public function ApplicationMediator( viewComponent:Object )
      {
         // pass the viewComponent to the superclass where
         // it will be stored in the inherited viewComponent property
         super( NAME, viewComponent );
      }
      public function get app():MultiAir{
         return viewComponent as MultiAir;
      }
      override public function onRegister( ):void
      {
         facade.registerMediator( new AppControlBarMediator( app.controlBar ) );
      }
      override public function listNotificationInterests():Array
      {
         return [ DesktopCitizenConstants.WINDOW_READY];
      }
      override public function handleNotification( note:INotification ):void
      {
         switch ( note.getName() ) {
            
            // Time to show the application window
            case DesktopCitizenConstants.WINDOW_READY:
               app.showControls = true;
               break;
         }
      }
   }
}

-----------------------------------------
AppControlBarMediator.as

package org.view
{
   import org.puremvc.as3.multicore.interfaces.*;
   import org.puremvc.as3.multicore.patterns.mediator.*;

   import org.ApplicationFacade;
   import org.view.components.AppControlBar;
   
   /**
    * A Mediator for interacting with the AppControlBar component.
    */
   public class AppControlBarMediator extends Mediator implements IMediator
   {
      // Cannonical name of the Mediator
      public static const NAME:String = 'AppControlBarMediator';
      
      public function AppControlBarMediator( viewComponent:Object )
      {
         super( NAME, viewComponent );
      }
      protected function get controlBar():AppControlBar{
         return viewComponent as AppControlBar;
      }
   }
}
---------------------------------
AppControlBar.mxml

<mx:ApplicationControlBar xmlns:mx="http://www.adobe.com/2006/mxml" dock="true">
   
   <mx:Script>
      <![CDATA[
      import org.ApplicationFacade;

      public static const BEGIN_CODE_SEARCH:String    = "beginCodeSearch";
      public static const CANCEL_CODE_SEARCH:String    = "cancelCodeSearch";
      
      [Bindable] public var comboOptions:Array;
      [Bindable] public var searching:Boolean = false;      
      
      /**
       * Initiate Code Search.
        */
       private function search() : void
       {
          searching=true;
           dispatchEvent( new Event( BEGIN_CODE_SEARCH ) );
       }
           
      /**
       * Cancel Code Search
        */
       private function cancel() : void
       {
          searching=false;
           dispatchEvent( new Event( CANCEL_CODE_SEARCH ) );
       }
           
      ]]>
   </mx:Script>
   
   <!-- The Search Controls -->
   <mx:HBox width="75%">
      <mx:ComboBox id="searchCombo" dataProvider="{comboOptions}" close="searchTI.setFocus()"/>
      <mx:TextInput id="searchTI" width="250" toolTip="Enter a language keyword or code fragment." enter="search()"/>
      <mx:Button label="Search" click="search()" enabled="{(searchTI.text.length != 0)&amp;&amp;(!searching)}" />
      <mx:Button label="Cancel" click="cancel()" visible="{searching}" />
      <mx:Label text="Searching..." fontFamily="Courier" fontSize="10" visible="{searching}"/>
   </mx:HBox>      
</mx:ApplicationControlBar>
--------------------
N.B. I took out the long comments for  readability's sake.

Ondina
Logged

~ Ondina ~
Pages: [1]
Print