3 Replies Latest reply on Dec 4, 2007 1:00 PM by GeorgeWS

    Dynamic Linkbar

    GeorgeWS Level 1
      This works:

      <mx:LinkBar width="100%" itemClick="navigateToURL(new URLRequest(' http://www.youngsmarket.com/youngsmarket/Employees/Main3.cfm?goto=' + String(event.label).toLowerCase()), 'Main')" selectionColor="#A5B6BE" rollOverColor="#A5B6BE" height="24">
      <mx:dataProvider>
      <mx:Array>
      <mx:String>Employee</mx:String>
      <mx:String>Director</mx:String>
      <mx:String>Warehouse</mx:String>
      </mx:Array>
      </mx:dataProvider>
      </mx:LinkBar>

      This Does Not:

      <mx:LinkBar width="100%" itemClick="navigateToURL(new URLRequest(' http://www.youngsmarket.com/youngsmarket/Employees/Main3.cfm?goto=' + String(event.label).toLowerCase()), 'Main')" selectionColor="#A5B6BE" rollOverColor="#A5B6BE" height="24">
      <mx:dataProvider>
      <mx:Array>
      <mx:String>{sResult.Employee}</mx:String>
      <mx:String>{sResult.Director}</mx:String>
      <mx:String>{sResult.Warehouse}</mx:String>
      </mx:Array>
      </mx:dataProvider>
      </mx:LinkBar>

      I want to dynamicaly create the linkbar the sResult comes from a RemoteObject call to a CFC. If I put the sResults in a mx:Label it shows the Employee (George), Director (1) and Warehouse (0). WHy wont it show up in the mx:String?

      Anyone?

      George
        • 1. Re: Dynamic Linkbar
          GeorgeWS Level 1
          I am so frustrated with Flex. I build really cool stuff but to understand each component is taking me forever more than a week for each component. There are never samples of what I want to do. Can anyone help with this concept? Please

          Im also able to do it like this but not dynamicaly from a db:

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

          <mx:LinkBar width="100%" itemClick="navigateToURL(new URLRequest(' http://www.youngsmarket.com/youngsmarket/Employees/Main2.cfm?goto=' + String(event.label).toLowerCase()), 'Main')" selectionColor="#A5B6BE" rollOverColor="#A5B6BE" height="24">
          <mx:dataProvider>
          {linkData}
          </mx:dataProvider>
          </mx:LinkBar>

          George
          • 2. Re: Dynamic Linkbar
            Level 7
            George,

            All data services calls, including RemoteObject calls, are asynchronous
            in Flex so you have to wait until the result is returned before you can use
            the data. You must also be sure that the returned result is of a type that
            is suitable for a data provider, so, while there are ways og achieving this
            in a smaller number of lines of code, when you're not familiar with this
            style of programming I suggest an explicit approach like the following:

            ...

            <mx:Script>
            import mx.collections.ArrayCollection;
            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.ResultEvent;
            import mx.utils.ArrayUtil;

            [Bindable]
            private var linkData:ArrayCollection;

            private function handleGetDataResult(event:ResultEvent):void
            {
            if (event.result is ArrayCollection)
            linkData = event.result as ArrayCollection;
            else
            linkData = new ArrayCollection(ArrayUtil.toArray(event.result));
            }

            private function handleFault(event:FaultEvent):void
            {
            // Always listen for faults when developing data based applications!
            }
            </mx:Script>


            <mx:RemoteObject id="myRemoteObject" destination="myDestination" fault="handleFault(event)">
            <mx:operation name="getData" result="handleGetDataResult(event)" />
            </mx:RemoteObject>


            <mx:LinkBar width="100%" itemClick="navigateToURL(new URLRequest(' http://www.youngsmarket.com/youngsmarket/Employees/Main2.cfm?goto='
            + String(event.label).toLowerCase()), 'Main')"
            selectionColor="#A5B6BE"
            rollOverColor="#A5B6BE" height="24">
            <mx:dataProvider>{linkData}</mx:dataProvider>
            </mx:LinkBar>

            ...

            Regards,
            Pete



            • 3. Re: Dynamic Linkbar
              GeorgeWS Level 1
              Thanks for the reply. Im not sure what your showing me in this part:

              private function handleGetDataResult(event:ResultEvent):void
              {
              if (event.result is ArrayCollection)
              linkData = event.result as ArrayCollection;
              else
              linkData = new ArrayCollection(ArrayUtil.toArray(event.result));
              }


              All I want to do is...

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

              EXCEPT I want the "Home","Director"... to be dynamic. Im sure I could build the string in the cfc and pass just one variable (dont know if thats best, but im thinking so due to variable number of commas).
              I just can get a variable in here...

              Bindable]
              private var linkData:Array = [myVARIABLE];

              I do pull in data to my nav app displaying name and employee number. I cant figure out why I cant even just put the employee variable where im showing myVariable above. Seem like that should work.

              Thanks
              George