6 Replies Latest reply on Oct 14, 2008 7:57 AM by Newsgroup_User

    Dynamic creation

    nkollipara
      Hi,
      I am newly learning the flex builder 3.0. I have an issue while dynamic creation and reading of data from the components (textinput, combobox etc.).
      The logic which I implemented for dynamic creation of the components is as below:


      public function dynamic2():void{
      var i:int;
      for(i=1;i<=n;i++){

      var vBox:VBox=new VBox();


      var hBox:HBox = new HBox();

      var tip1:TextInput=new TextInput();
      tip1.text=”hai”;
      var combobox:ComboBox=new ComboBox();
      combobox.dataProvider=datatypes1;
      //Add components to hbox
      hBox.addChild(tip1);
      hBox.addChild(combobox);
      //Add hbox to vbox
      vBox.addChild(hBox);
      //Add vbox to tile
      //Here maintile is Static tile and we are adding dynamic components to it
      maintile.addChild(vBox);
      }
      i=0;
      }

      In the for loop ‘n’ value is entered by the user based on that value we need to load the dynamic components. I am able generate the components, but the problem is we are not able to read the data from components(textinput and combobox) because we are not able to differentiate the components if multiple times the for loop is repeated.

      Is there any concept where we can generate array of components
      For example:
      This syntax is existing in flex for array variable creation
      Var arr:Array=new Array(5);

      Do we have any concept like the above to create array of components?
      Like wise var tip:TextInput=new TextInput(5);

      Or suggest any solution for reading of dynamic values and identify those components separately?

      Thanks in advance
      Nagaraju
        • 1. Re: Dynamic creation
          Level 7

          "nkollipara" <webforumsuser@macromedia.com> wrote in message
          news:gcnhta$sqk$1@forums.macromedia.com...
          > Hi,
          > I am newly learning the flex builder 3.0. I have an issue while
          > dynamic
          > creation and reading of data from the components (textinput, combobox
          > etc.).
          > The logic which I implemented for dynamic creation of the components is
          > as
          > below:
          >
          >
          > public function dynamic2():void{
          > var i:int;
          > for(i=1;i<=n;i++){
          >
          > var vBox:VBox=new VBox();
          >
          >
          > var hBox:HBox = new HBox();
          >
          > var tip1:TextInput=new TextInput();
          > tip1.text=?hai?;
          > var combobox:ComboBox=new ComboBox();
          > combobox.dataProvider=datatypes1;
          > //Add components to hbox
          > hBox.addChild(tip1);
          > hBox.addChild(combobox);
          > //Add hbox to vbox
          > vBox.addChild(hBox);
          > //Add vbox to tile
          > //Here maintile is Static tile and we are adding dynamic components to it
          > maintile.addChild(vBox);
          > }
          > i=0;
          > }
          >
          > In the for loop ?n? value is entered by the user based on that value we
          > need
          > to load the dynamic components. I am able generate the components, but the
          > problem is we are not able to read the data from components(textinput and
          > combobox) because we are not able to differentiate the components if
          > multiple
          > times the for loop is repeated.
          >
          > Is there any concept where we can generate array of components
          > For example:
          > This syntax is existing in flex for array variable creation
          > Var arr:Array=new Array(5);
          >
          > Do we have any concept like the above to create array of components?
          > Like wise var tip:TextInput=new TextInput(5);
          >
          > Or suggest any solution for reading of dynamic values and identify those
          > components separately?

          Quick answer:

          Keep an array that refers to all the HBoxes.

          Long answer: you're probably better off using a Repeater and letting it
          create the Array for you:
          http://livedocs.adobe.com/flex/3/html/help.html?content=repeater_3.html


          • 2. Re: Dynamic creation
            nkollipara Level 1
            Please let me know how to create a dynamic hbox array and how to use repeater

            The problem is the hboxes or whatever components we are using we are not able to identify them because for all things we are having a single id. we parse single id the repeater will repeat only once (with a single id we are generating multiple hboxes or all the components)
            • 3. Dynamic creation
              nkollipara Level 1
              Thanks a lot for yours quick reply.

              Please let me know how to create a dynamic hbox array and how to use repeater

              The problem is the hboxes or whatever components we are using we are not able to identify them because for all things we are having a single id. we parse single id the repeater will repeat only once (with a single id we are generating multiple hboxes or all the components)

              please help me in this issue

              once again thanks in advance
              • 4. Re: Dynamic creation
                Level 7

                "nkollipara" <webforumsuser@macromedia.com> wrote in message
                news:gcuq4i$djp$1@forums.macromedia.com...
                > Please let me know how to create a dynamic hbox array and how to use
                > repeater
                >
                > The problem is the hboxes or whatever components we are using we are not
                > able
                > to identify them because for all things we are having a single id. we
                > parse
                > single id the repeater will repeat only once (with a single id we are
                > generating multiple hboxes or all the components)

                I'm sorry, was the link to the repeater docs that I posted not clickable for
                you? Or was there a specific concept in the docs that you were having
                trouble with? I'm having trouble understanding what you're actually asking.


                • 5. Re: Dynamic creation
                  nkollipara Level 1
                  Thanks for the reply

                  Please let me know the syntax: how to create hbox array?
                  • 6. Re: Dynamic creation
                    Level 7

                    "nkollipara" <webforumsuser@macromedia.com> wrote in message
                    news:gd17lo$eds$1@forums.macromedia.com...
                    > Thanks for the reply
                    >
                    > Please let me know the syntax: how to create hbox array?

                    If you look at the link I posted, under "Referencing Repeated components",
                    pretend that instead of "VBox" the code says "HBox" in the second example.