On 12/17/06, Stephen Hueners <[EMAIL PROTECTED]> wrote:
Seems like the MVC pattern would be a natural fit for a menuing system that
has to keep track of things like logged user various button states and
actions. I'm looking for a sample of AS2 code being used to build a menuing
system.

Kind of depends on what your states and actions are. Here's a good basis:

/**
* Model class that stores data for one menu item.
f *
* <p>Optionally has child items.</p>
*/
class menu.MenuItem {
   /**
    * Label for this item.
    */
   public function get label():String;
   /**
    * Number if child items (nonnegative integer).
    */
   public function get childCount():Number;
   /**
    * Retrieves a child item.
    *
    * @param  index  Index of child item, nonnegative integer less
than [EMAIL PROTECTED] #childCount}.
    */
   public function getChild(index:Number):MenuItem;
   /**
    * Reads data from an XML node.
    *
    * @param  node   XML node with menu item data.
    * @throws  Error  If [EMAIL PROTECTED] node} is not properly formatted.
    */
   public function readXMLNode(node:XMLNode):Void;
}

import menu.MenuItem;
import mx.events.EventDispatcher;
[Event("currentChange")]
/**
* Controller class that keeps track of the currently-selected item.
*/
class MenuController extends EventDispatcher {
   /**
    * Currently-selected menu item.
    */
   [Bindable(event="currentChange")]
   public function get currentItem():MenuItem;
   public function set currentItem(item:MenuItem):Void;
}

import menu.MenuController;
import menu.MenuItem;
/**
* Menu item component.
*/
class menu.MenuItemView extends MovieClip {
   /**
    * Creates a new instance referring to a specific item.
    *
    * @param  parent  Parent movie clip.
    * @param  controller  Object that controls the menu.
    * @param  item  Menu item model object.
    * @return  New instance of this class.
    */
   public static function create(parent:MovieClip, controller:MenuController,
       item:MenuItem):MenuItemView;
   /**
    * The item that this component refers to.
    */
   public function get item():MenuItem;
}

MenuView components could then listen to MenuController.instance for
"currentChange" events and update whether or not they are enabled or
disabled. Further attributes could be added to MenuItem (id, type,
selectable, whatever). MenuController could also be used to keep track
of other things. It might also be a good idea to create a Menu class
for containing top-level MenuItem objects, with a corresponding
MenuView class for containing top-level MenuItemView object.

There are a lot of different things you could do with this basic MVC
setup, depending on what you need.
--
T. Michael Keesey
The Dinosauricon: http://dino.lm.com
Parry & Carney: http://parryandcarney.com
ISPN Forum: http://www.phylonames.org/forum/
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to