Tim

Yes, it can be done but it ain't easy.

I have just completed an application that creates form items on the
fly from a database. The PHP code returns value objects with fields
including FieldName, FieldLabel, FieldType etc.

So, first, I create a custom class that extends Form. Then, in the
constructor, I ask for the field data with a RemoteObject call. Once I
get the data back, I loop through the value objects and create a form
field as specified...

for(var i:int ; i < FormFieldsArrColl.length ; i++)
{
   var theFormItem:FormItem = new FormItem();
   switch(currentFormField.FieldType) // currentFormField is my VO type
   {
      case "textinput":
         var theTextInputItem:TextInput = new TextInput();
         addTextInputFormItem(theFormItem, theTextInputItem,
currentFormField);
   }
}

The addTextInputFormItem function looks like this...

private function addTextInputFormItem(aFormItem:FormItem,
aTextInputItem:TextInput, theFormField:MyFormField):void
{
   if(theFormField.Required) {aFormItem.required = true;}
   aFormItem.setStyle("fontWeight", "bold");
   aTextInputItem.setStyle("fontWeight", "normal");
   aTextInputItem.id = theFormField.FieldName;
   aTextInputItem.width = 300;
   aFormItem.label = theFormField.FieldLabel + ":";
   aTextInputItem.text = theFormField.FieldDefaultText;
   aFormItem.addChild(aTextInputItem);
   this.addChild(aFormItem);
}

There are case items and functions for all the other field types
(TextArea, Checkbox and RadioButtons) but I will leave those
definitions for you to figure out ;-}

Then, once everything has been set up you need to add a submit button
and then loop through all the fields and validate them (Correct data
type, Values specified for required fields etc) and finally send all
this data back to the server.

Of course, I have extended mine even more with fields that depend on
other fields and animation to show different fields.

--- In [email protected], "timgerr" <[EMAIL PROTECTED]> wrote:
>
> Can a Repeater be done in ActionScript?  Can a form be created in
> ActionScript?
> 
> Thanks for the help,
> timgerr



Reply via email to