3 Replies Latest reply on May 7, 2008 7:15 AM by levancho

    Dynamically Generate TextInput

    flatpickinJohn Level 1
      I want to create a contact information for to the attached code. The code adds or deletes vboxes. I want the vboxes to include user input fields.
        • 1. Re: Dynamically Generate TextInput
          Gregory Lafrance Level 6
          If you want user input, how about just using TextInput.

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
          <mx:Script>
          <![CDATA[
          import mx.containers.VBox;
          import mx.controls.TextInput;
          private const MAX_CHILDREN:uint = 5;
          private function accordion_addChild():void {
          if (accordion.numChildren < MAX_CHILDREN) {
          var vbox:VBox = new VBox();
          var field:TextInput = new TextInput();
          vbox.addChild(field);
          vbox.label = "child " + accordion.numChildren;
          vbox.percentWidth = 100;
          vbox.percentHeight = 100;
          var randColor:uint = Math.random() * 0xFFFFFF;
          vbox.setStyle("backgroundColor", randColor);
          accordion.addChild(vbox);
          }
          }

          private function accordion_deleteChild():void {
          if (accordion.selectedChild) {
          accordion.removeChild(accordion.selectedChild);
          }
          }
          ]]>
          </mx:Script>
          <mx:ApplicationControlBar dock="true">
          <mx:Button label="Add child"
          click="accordion_addChild();" />
          <mx:Button label="Delete child"
          click="accordion_deleteChild();" />
          </mx:ApplicationControlBar>
          <mx:Accordion id="accordion" width="240" height="160" />
          </mx:Application>
          • 2. Re: Dynamically Generate TextInput
            flatpickinJohn Level 1
            What I'm trying to do is create a contact information form and be able to create/delete them in an accoridian. The example above allows me to create/delete vboxes in accordian but I'm having trouble figuring out how to replace the vbox with a contact information form. I created one as a flex project and was thinking about instantiating it as a class and using it in my action script. Or to create it directily in actionscript which seems to be causing me problems.
            • 3. Dynamically Generate TextInput
              levancho Level 3
              you can do that, just create a component out of that form and form fields ....
              for example MYFormComponent.mxml
              and inside you have whatever you need,
              <mxForm etc ....

              then in action script you can instantiate your component and add it accordion as a child .
              private var myComp:MYFormComponent;
              private function accordion_addChild():void {
              if (accordion.numChildren < MAX_CHILDREN) {
              if(!myCOmp) myCOmp = new MYFormComponent();
              myCOmp.whateverproerty= whatevervalue
              ....


              accordion.addChild(myCOmp);

              }
              }