2 Replies Latest reply on Sep 22, 2006 8:14 PM by peterent

    Display of Dynamic data in combo (created on the fly)

    Like2Flex Level 1
      Hi,

      I am using an accordion in which I am creating dynamic controls (combobox), named "cb". Each tab has the combo (cb) created in it. Then I've got a function which derives market from my backend using remote object with coldfusion. I want to display the market in the combo. How do I use the function with my "cb" Below is my code. My combo remains blank upon loading the accordion. Am getting error in the last 3 lines of the function.


      Thx



      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="Init()">

      <mx:Script>
      <![CDATA[
      //import mx.collections.*;
      import mx.collections.ArrayCollection;
      import mx.rpc.events.ResultEvent;
      import mx.controls.Alert;
      import mx.events.CloseEvent;
      import flash.events.Event;
      import mx.containers.*;
      import mx.controls.*;


      public function Init():void
      {
      myService.getMarket();
      }


      [Bindable] public var market:ArrayCollection= new ArrayCollection();


      public function addcontrols():void
      {
      var newHB:HBox = new HBox()
      var canvas:Canvas = new Canvas() //Create a canvas
      var btn:Button = new Button()
      var cb:ComboBox = new ComboBox()

      canvas.addChild(newHB)
      canvas.addChild(cb)
      accordion.addChild(canvas) //Add to accordion
      cb.y=20
      }

      public function getMarket(event:ResultEvent):void
      {
      market=event.result as ArrayCollection;
      cb.dataProvider=market; '//ERROR HERE
      cb.labelField="Market_Name"; //ERROR HERE
      cb.selectedIndex=0; //ERROR HERE
      }


      //Array of created containers
      // private var hBoxes:Array = [];
      //
      //public function addHB():void {
      // Create new HBox container.
      // var newHB:HBox = new HBox();
      // var newcb:ComboBox=new ComboBox();
      // newHB.label="New Break-Down" //: " + String(hBoxes.length);

      // Add it to the Accordion container, and to the Array of HBox containers.
      //hBoxes.push(accordion.addChild(newHB));
      // }

      // public function delHB():void {
      // If there is at least one HBox container in the Array, remove it.
      // if (hBoxes.length >=1) {
      // accordion.removeChild(hBoxes.pop());
      //}
      //}



      ]]>
      </mx:Script>

      <mx:RemoteObject
      id="myService"
      destination="ColdFusion"
      source="components.DCS">
      <mx:method name="getMarket" result="addcontrols()" fault="Alert.show(event.fault.message)" />
      </mx:RemoteObject>



      <mx:Panel x="10" y="10" width="1260" height="451" layout="absolute">

      <mx:Accordion id="accordion" x="10" y="24" width="1220" height="335">
      <mx:Canvas label="1" width="100%" height="265">
      </mx:Canvas>
      </mx:Accordion>

      <mx:Button label="Add Controls" click="Init();" x="10" y="367" width="102"/>

      </mx:Panel>



      </mx:Application>
        • 1. Re: Display of Dynamic data in combo (created on the fly)
          ntsiii Level 3
          Maybe a timing issue?

          When do you run addControls()?

          Perhaps you should call getMarket() using callLater at the end of addControls?

          Or call it on the creationComplete of the Accordion.

          Tracy
          • 2. Re: Display of Dynamic data in combo (created on the fly)
            peterent Level 2
            Your logic flow:

            1. Clicking button "Add Controls" calls init();
            2. init() calls myService.getMarket(); a remote data call, the result handler is addcontrols();
            3. addcontrols() creates: an HBox, a Canvas, a Button, and a ComboBox
            4. the HBox and ComboBox are added to the Canvas; the Canvas is added to the Accordion.

            q1: In step 4, what happens to the Button?
            q2: when and where does public function getMarket get called? It is written as though it were a result handler for a RemoteObject, but your result handler for myService.getMarket() is addcontrols() - step 2/3.

            I think you need to combine the getMarket() result handler and addcontrols().