<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:cc="customComponents.*"
layout="absolute" creationComplete="init()"
width="100%" height="100%"
backgroundGradientColors="[#ffffff, #ffffff]" viewSourceURL="srcview/index.html">
<mx:Script>
<![CDATA[
import customComponents.CustomTextInput;
import mx.collections.ArrayCollection;
import mx.containers.FormItem;
import mx.core.Container;
import mx.rpc.events.ResultEvent;
import mx.controls.Alert;
private var aFormFields:Array = new Array();
private function init():void{
formsService.send();
}
private function xmlReturned(event:ResultEvent):void{
var rawXML:XML = event.result as XML;
for each (var n:XML in rawXML.displayObjectContainer.displayObject){
var newObjectContainer:FormItem = new FormItem();
newObjectContainer.label = n.label;
var newObject:CustomTextInput = new CustomTextInput();
newObject.addEventListener("change",saveEvent);
newObject.custom_id = n.id;
newObject.text = n.text;
addObjectToArray(newObject);
newObjectContainer.addChild(newObject);
myDynamicForm.addChild(newObjectContainer);
}
}
private function addObjectToArray(formField:DisplayObject):void{
this.aFormFields.push(formField);
}
private function saveEvent(event:Event):void{
var i:int;
var tempAFormIDS:Array = new Array(); var tempAFormValues:Array = new Array(); var tempIDList:String;
for(i = 0; i < aFormFields.length; i++){
tempAFormIDS.push(aFormFields[i]['custom_id']);
tempAFormValues.push(aFormFields[i]['text']);
}
tempIDList = tempAFormIDS.toString();
formIDS.text = tempIDList;
formValues.text = tempAFormValues.toString();
}
]]>
</mx:Script>
<mx:HTTPService id="formsService" url="assets/data/MyForms.xml" result="xmlReturned(event)" resultFormat="e4x" />
<mx:VBox width="100%" height="100%">
<mx:HBox width="100%" height="50%">
<mx:Form id="myDynamicForm">
</mx:Form>
<mx:Button label="Save" click="saveEvent(event)"/>
</mx:HBox>
<mx:HBox width="100%" height="50%">
<mx:Label text="the form id's"/>
<mx:TextArea id="formIDS"/>
<mx:Label text="the form values"/>
<mx:TextArea id="formValues"/>
</mx:HBox>
</mx:VBox>
</mx:Application>