27.6. Create a New Command

Creating a new command actually does several things:

  • Creates a command class.

  • Creates an event class.

  • Registers the event and command class in the default controller.

To create a new command, do the following:

  1. Right-click your project in the Flex Navigator and select New Cairngorm Command (Figure 27-29).

    Figure 27.29. Figure 27-29
  2. In the New Cairngorm Event and Command dialog (Figure 27-30) do the following:

    1. Enter a name for the event in the Event name field.

    2. Enter the event class name in the Event class field.

    3. Enter the command class name in the Command class field.

    4. Click Finish.

Figure 27.30. Figure 27-30

The process generates the following classes:

LoginEvent:

package com.cairngormplugin.events
{
   import com.adobe.cairngorm.control.CairngormEvent;
   import flash.events.Event;
   public class LoginEvent extends CairngormEvent
   {
      public static const EVENT_NAME : String = "login";
      public function LoginEvent( bubbles : Boolean = false,
      cancelable : Boolean = false )
      {
         super( EVENT_NAME, bubbles, cancelable );
}
      public override function clone() : Event
      {
         return new LoginEvent( bubbles, cancelable );
      }
   }
}

LoginCommand:

package com.cairngormplugin.commands { import com.adobe.cairngorm.commands.Command; ...

Get Professional Cairngorm™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.