4 Replies Latest reply on Sep 20, 2006 1:03 AM by Like2Flex

    Create controls on the fly in Accordion

    Like2Flex Level 1
      Hello,

      I am using an Accordion in my project. I actually have 3 tabs in the Accordion. My application works as follows :
      When I load the browser, the first tab of my Accordion is displayed by default showing a combobox (named : combo1). I also have a button on the first tab (button1). The purpose of the button is to create child tabs in the accordion. When I press the button it should create the second tab (this is done). But I also want to create the combo1 dynamically as well as the button1 so that as I move on, the following tabs show me the controls as in the previous tab. How to do?

      Should I create the first control in the first tab manually or can it be done dynamically as well. Note that the purpose of the combo is to display values from a database table upon click.

      Pls help
      Thx
        • 1. Re: Create controls on the fly in Accordion
          hsivaram
          use addChild() on the accordion to add your buttonand comboBox ...
          ex:

          var canvas:Canvas = new Canvas() //Create a canvas
          var btn:Button = new Button()
          btn.addEventListener("click", addAnother);
          var cb:ComboBox = new ComboBox()
          canvas.addChild(cb)
          canvas.addChild(btn)
          acc.addChild(cvs); //Add to accordion

          Hope this helps
          Harish
          • 2. Re: Create controls on the fly in Accordion
            inlineblue Level 1
            If you want all your tabs to look the same, then it's best to create a custom MXML component (based on Canvas, for example) to store the layout. Then create instances of that component and add them as children to the accordion.
            • 3. Re: Create controls on the fly in Accordion
              Like2Flex Level 1
              I created controls on the fly. It working fine. Now I want to do data binding to the controls. Am using Remote Object with ColdFusion as destination. The function getMarket below should populate the combo (cb). It is giving error in the last 3 lines of the GetMarket function. Is there somthing wrong here?


              [Bindable]

              public var market:ArrayCollection= new ArrayCollection();
              public var trader: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()

              //btn.addEventListener("click", addAnother);
              canvas.addChild(newHB)
              canvas.addChild(cb)
              canvas.addChild(btn)
              accordion.addChild(canvas); //Add to accordion
              newHB.label="New Break-Down"
              }

              public function getMarket(event:ResultEvent):void
              {
              market=event.result as ArrayCollection;
              cb.dataProvider=market;
              cb.labelField="Market_Name";
              cb.selectedIndex=0;
              }
              • 4. Re: Create controls on the fly in Accordion
                Like2Flex Level 1
                I can't understand. COuld you please be more specific with some example of sample code. thx