DropDownMenuItem.as

Go to the documentation of this file.
00001 
00005 import mx.utils.Delegate;
00006 
00007 import flash.geom.Point;
00008 
00009 import gugga.common.ITask;
00010 import gugga.navigation.DropDownMenuItemTitle;
00011 import gugga.navigation.IDropDownMenuItem;
00012 import gugga.navigation.INavigationItem;
00013 import gugga.navigation.MenuItemsController;
00014 
00015 [Event("selected")]
00016 class gugga.navigation.DropDownMenuItem 
00017         extends MenuItemsController 
00018         implements IDropDownMenuItem
00019 {
00020         private var mHitAreaClip:MovieClip;
00021         private var mTitleButton:DropDownMenuItemTitle;
00022         private var mIsSelected:Boolean = false;
00023         private var mHitTestBoundingBox:Boolean = false;
00024         
00025         private var mOpeningTask:ITask;
00026         private var mClosingTask:ITask;
00027         
00028         public function get HitTestBoundingBox():Boolean { return mHitTestBoundingBox; }
00029         public function set HitTestBoundingBox(aValue:Boolean):Void { mHitTestBoundingBox = aValue; }
00030         
00031         public function get IsSelected():Boolean { return mIsSelected; }
00032         public function get SelectedSubItem():INavigationItem { return mSelectedSubItem; }
00033         public function get SelectedSubItemID():String { return mSelectedSubItemID; }
00034         
00035         public function DropDownMenuItem()
00036         {
00037                 mHitAreaClip = this;
00038         }
00039         
00040         public function registerTitleButton(aDropDownMenuItemTitle:DropDownMenuItemTitle):Void
00041         {
00042                 if(mTitleButton)
00043                 {
00044                         mTitleButton.removeEventListener("click", Delegate.create(this, onTitleButtonClick));
00045                         mTitleButton.removeEventListener("rollOver", Delegate.create(this, onTitleButtonRollOver));
00046                 }
00047                 
00048                 mTitleButton = aDropDownMenuItemTitle;
00049                 mTitleButton.addEventListener("click", Delegate.create(this, onTitleButtonClick));
00050                 mTitleButton.addEventListener("rollOver", Delegate.create(this, onTitleButtonRollOver));
00051         }               
00052         
00053         public function registerChildTitleButton(aInstanceName:String):DropDownMenuItemTitle
00054         {
00055                 var dropDownMenuItemTitle:DropDownMenuItemTitle = DropDownMenuItemTitle(this[aInstanceName]);
00056                 registerTitleButton(dropDownMenuItemTitle);
00057                 return dropDownMenuItemTitle;
00058         }
00059         
00060         private function onTitleButtonClick(ev)
00061         {
00062                 dispatchEvent({type:"selected", target:this});
00063         }
00064 
00065         private function onTitleButtonRollOver(ev)
00066         {
00067                 mTitleButton.playRollOver(); //TODO: can be called by the child class, not here
00068                 dispatchEvent({type:"rollOver", target:this});
00069         }
00070         
00071         private function onMeRollOut()
00072         {
00073                 mTitleButton.playRollOut(); //TODO: can be called by the child class, not here
00074                 dispatchEvent({type:"rollOut", target:this});
00075         }
00076         
00077         private function onEnterFrameHandler(){
00086                 var mouseCoordinates : Point = new Point(mHitAreaClip._xmouse, mHitAreaClip._ymouse);
00087                 mHitAreaClip.localToGlobal(mouseCoordinates);
00088 
00089                 if(!mHitAreaClip.hitTest(mouseCoordinates.x, mouseCoordinates.y, !mHitTestBoundingBox)){
00090                         onMeRollOut();
00091                 }
00092         }
00093 
00094         public function registerOpeningTask(aTask:ITask):Void
00095         {
00096                 mOpeningTask = aTask;
00097         }               
00098 
00099         public function registerClosingTask(aTask:ITask):Void
00100         {
00101                 mClosingTask = aTask;
00102         }
00103         
00104         public function setHitArea(aHitAreaClip:MovieClip):Void
00105         {
00106                 mHitAreaClip = aHitAreaClip;
00107         }       
00108         
00109         public function select():Void 
00110         {
00111                 if(!mIsSelected)
00112                 {
00113                         mIsSelected = true;
00114                         mTitleButton.select();
00115                 }
00116         }
00117 
00118         public function unselect():Void 
00119         {
00120                 if(mIsSelected)
00121                 {
00122                         mIsSelected = false;
00123                         mTitleButton.unselect();
00124                         unselectAllSubItems();//This code is present in VanileRoyal's version. Majbe it fixes a bug.
00125                 }
00126         }
00127 
00128         public function show():Void 
00129         {
00130                 super.show();
00131                 mTitleButton.show();
00132         }       
00133 
00134         public function hide():Void 
00135         {
00136                 super.hide();
00137                 mTitleButton.hide();
00138         }       
00139         
00140         public function open():Void 
00141         {
00142                 mTitleButton.playRollOver();//This code is present in VanileRoyal's version. Majbe it fixes a bug.
00143                 this.onEnterFrame = onEnterFrameHandler;
00144                 
00145                 if(mOpeningTask)
00146                 {
00147                         mOpeningTask.start();
00148                 }
00149                 else
00150                 {
00151                         showAllSubItems();
00152                 }
00153         }
00154 
00155         public function close():Void 
00156         {
00157                 mTitleButton.playRollOut();//This code is present in VanileRoyal's version. Majbe it fixes a bug.
00158                 this.onEnterFrame = null;
00159                 
00160                 if(mClosingTask)
00161                 {
00162                         mClosingTask.start();
00163                 }
00164                 else
00165                 {
00166                         hideAllSubItems();
00167                 }
00168         }
00169 }

Generated on Fri May 11 17:12:42 2007 for GuggaFramework by  doxygen 1.5.2