1 Reply Latest reply on Nov 17, 2009 9:51 AM by frogman.pep

    MenuBar Issue

    frogman.pep

      Click here to see this issue.  If you click on Portfolio menu you'll get the error "Undefined State Name, 'Portfolio.'  My question is how to I disable the Portfolio menu?  I found a thread earlier about writing an if statement if the menu has submenus but can't find it anymore.  The attached code is as follows:

       

      Index.mxml

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"       
          creationComplete="init()"
          xmlns:comp="components.*"
          layout="absolute"
          verticalScrollPolicy="off"
          horizontalScrollPolicy="off">

      <mx:Style source="assets/css/style.css"/>

      <mx:Script>
        <![CDATA[
         import mx.rpc.events.*;
         import mx.collections.*;
         import mx.events.MenuEvent;
         import mx.events.ItemClickEvent;
         import mx.resources.*;
        
         [Bindable]
         public var pic:ArrayCollection;
        
         [Bindable]
         private var menuData:ArrayCollection;  

         [Bindable]
         public var tileData:ArrayCollection;
           
         private function picHandler(event:ResultEvent):void{
          pic = event.result.pics.image;
          trace(pic);
         }
        
         private function init():void{
          IllustrationDataIn.send();
          var menuItems:Array = new Array();
         
          menuItems.push({label:"Home"});
        
          var subMenuItems:ArrayCollection = new ArrayCollection([{label:"Illustration"}, {label:"Texturing"}, {label:"Modeling"}, {label:"Instructional"}])
          menuItems.push({label:"Portfolio", children:subMenuItems});
         
          menuItems.push({label:"Resume"});
         
          menuItems.push({label:"Contact"});
         
          menuData = new ArrayCollection(menuItems);
          // trace(menuData);
         
          //systemManager.addEventListener(MouseEvent.MOUSE_WHEEL, onMouseWheel);   
         }
        
         private function menuClick(e:MenuEvent):void{
          var picItems:Array = new Array();
          var selectedItem:String = e.label;
          currentState=selectedItem;
         
          for each(var item:Object in tileData){
           if(selectedItem == item.category){     
            picItems.push(item)                    
           }
           tileData = new ArrayCollection(picItems);
           
           trace("Tile Data:");
           trace(tileData);
              
          }
         }
        
         private function topMenuClick(e:MouseEvent):void{
          var MenuItems:Array = new Array();
          var selectedItem:String = e.target.data.label;
          currentState=selectedItem;
          /*trace("hi");
          trace(selectedItem);*/
         
          for each(var item:Object in tileData){
           if(selectedItem == item.category){     
            MenuItems.push(item)
           }
          
           tileData = new ArrayCollection(MenuItems);
          }
         }
        ]]>
      </mx:Script>

      <mx:HTTPService id="IllustrationDataIn"
          url="assets/data/Illustration.xml"
          result="picHandler(event)"/>   

      <mx:states>
        <mx:State name="Home">
          <mx:AddChild>
           <comp:Home x="0" y="200"
              height="20%" width="100%"/>    
          </mx:AddChild>
         </mx:State>
        <mx:State name="Illustration">
          <mx:AddChild>
           <comp:Illustration x="0" y="0"
                height="100%" width="100%"
                picData="{pic}"/>
          </mx:AddChild>
         </mx:State>
      </mx:states>

      <mx:HBox  width="30%" height="5%"
          right="0">
          <mx:MenuBar id="menuList"                  
            labelField="label"   
            click="{topMenuClick(event)}"
            itemClick="{menuClick(event)}"
               dataProvider="{menuData}"
               width="100%"        
               right="0"                 
               height="100%"        
               fontSize="18"
               alpha="60"
               borderColor="#676d76"/>
      </mx:HBox>

      </mx:Application>

        • 1. Re: MenuBar Issue
          frogman.pep Level 1

          Figured this out while not really thinking bout it, just kind of came to me.  Probably not the most sound way and not the way I was reading about earlier dealing with top level menus or something like that, but since there is only one condition that needs to be dealt with this should work just fine.  Wrote an if / else statement like so:

           

          if (selectedItem != "Portfolio"){

          currentState=selectedItem;

          }else{

          currentState == currentState;

          }


          for each(var item:Object in tileData){

          if(selectedItem == item.category){

          MenuItems.push(item)

          }


          tileData = new ArrayCollection(MenuItems);

          }

          }

          If any one does now the other way I was thinking bout please fire away, know hopefully I can figure out my other dilema while not even thinking bout it :)..