tags:

views:

539

answers:

2

I need to generate a mx:form from an xml file that I am getting from httpservice.

Also I need to prefill the data that I am getting from the form itself.

Can someone give me a sample code?

A: 

Check this out: MXMLLoader for Flex 3. HTH.

David Hanak
+3  A: 

You would have to expand on this obviously, but this is how I would go about building a dynamic form..

      import mx.controls.TextInput;
  import mx.containers.FormItem;
  import mx.containers.Form;
  private var fxml:XML = 
  <form>
   <fields>
    <field type="text" label="name" default="gary"/>
    <field type="text" label="surname" default="benade"/>
   </fields>
  </form>

  private function init():void
  {
   var form:Form = new Form();
   form.setStyle("backgroundColor", 0xFFFFFF);
   for each( var xml:XML in fxml..field)
   { 
    switch( [email protected]())
    {
     case "text":
      var fi:FormItem = new FormItem();
      fi.label = xml.@label;
      var ti:TextInput = new TextInput();
      ti.text = [email protected]();
      fi.addChild( ti);       
      form.addChild( fi);
     break;
     case "int":
     break;
    }
   }    
   this.addChild( form);
  }
Gary Benade