3 Replies Latest reply on Jan 10, 2008 5:35 AM by m_hartnett

    LinkBar selection

    GeorgeWS Level 1
      I have a linkbar that is populated from an array (linkData):

      [Bindable]
      private var linkData:Array = [{label:"Home",data:Employee}, {label:"Directory",data:Employee}, {label:"Documents",data:Employee}, {label:"E-Mail",data:Employee}, {label:"Reports",data:Employee}, {label:"Tools",data:Employee}, {label:"Training",data:Employee}, {label:"HR",data:Employee}];

      I have my linkbar like this:

      <mx:LinkBar id="myBar" width="100%" itemClick="barNav()" selectionColor="#A5B6BE" rollOverColor="#A5B6BE" height="24">
      <mx:dataProvider>
      {linkData}
      </mx:dataProvider>
      </mx:LinkBar>

      When Clicked it does this action script:

      public function barNav() : void {
      var url:String = " http://www.youngsmarket.com//Main.cfm";
      var variables:URLVariables = new URLVariables();
      variables.goto = THIS IS MY TROUBLE: GETTING THE SELECTED LABEL FROM THE ARRAY;
      variables.Employee = sResult.getItemAt(0).Employee;
      variables.SupComp = sResult.getItemAt(0).SupComp;
      var request:URLRequest = new URLRequest(url);
      request.data = variables;
      try {
      navigateToURL(request, 'Main');
      }
      catch (e:Error) {
      // handle error here
      }
      }

      The Employee ans SupComp work great because they come from a result of an RO call returned as an Object.
      How can I get the LABEL of what is selected?

      Thanks
      George
        • 1. Re: LinkBar selection
          m_hartnett Level 3
          I think this is what you are looking for:
          var item : LinkButton = linkBar.getChildAt(linkBar.selectedIndex) as LinkButton;
          Alert.show(item.label,"");
          • 2. Re: LinkBar selection
            GeorgeWS Level 1
            Im not sure what you are telling me?
            • 3. Re: LinkBar selection
              m_hartnett Level 3
              Here is your code modified code. The alert is only there to show you the label. This code will show you the label of the link item that was clicked.

              <mx:Application
              xmlns:mx=" http://www.adobe.com/2006/mxml"
              layout="absolute" >

              <mx:Script>
              <![CDATA[
              import mx.controls.Alert;
              import mx.controls.LinkButton;
              import mx.containers.Canvas;


              [Bindable]
              private var linkData: Array = [{label:"Home",data:"Employee"},
              {label:"Directory",data:"Employee"},
              {label:"Documents",data:"Employee"},
              {label:"E-Mail",data:"Employee"},
              {label:"Reports",data:"Employee"},
              {label:"Tools",data:"Employee"},
              {label:"Training",data:"Employee"},
              {label:"HR",data:"Employee"}];



              public function barNav() : void {
              var url:String = " http://www.youngsmarket.com//Main.cfm";
              var variables:URLVariables = new URLVariables();

              var item : LinkButton = myBar.getChildAt(myBar.selectedIndex) as LinkButton;
              Alert.show(item.label,"");
              variables.goto = item.label;
              //variables.Employee = sResult.getItemAt(0).Employee;
              //variables.SupComp = sResult.getItemAt(0).SupComp;
              var request:URLRequest = new URLRequest(url);
              request.data = variables;

              }





              ]]>
              </mx:Script>
              <mx:LinkBar id="myBar" width="100%" itemClick="barNav()" selectionColor="#A5B6BE" rollOverColor="#A5B6BE" height="24">
              <mx:dataProvider>
              {linkData}
              </mx:dataProvider>
              </mx:LinkBar>


              </mx:Application>