Go Back   CodingForums.com > :: Client side development > Flash & ActionScript > Adobe Flex

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-06-2008, 06:47 PM   PM User | #1
revenekorb
New to the CF scene

 
Join Date: Sep 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
revenekorb is an unknown quantity at this point
Nested Loops for Dynamic ComboBox -- Newbie easy fix??

I have a dynamic xml driven form that I am trying to get the "label" and "value" using nested for loops for the combobox. I am using "droplabel" attribute. The xml schema is final, I cannot change this.

I am having problem targeting the child node attributes.

I keep running into error: "A term is undefined and has no properties." I am sure I am not properly formatting the for loop statement.

I thank anyone for helping me in advance.

---------------------------------------------------------------
XML:

<?xml version="1.0" encoding="utf-8?>

<formdata userid="davis" fname="David" lname="washingon" auth="1">

<element position="1" questionlabel="What is todays time ?">
<item id="1" inputtype="TextInput">Monday</item>
<item id="222" inputtype="TextInput">tonday</item>
</element>


<element position="5" questionlabel="What is your time of arrival ?">
<item id="5" inputtype="ComboBox">
<drop droplabel="Select Answer---" dropvalue="0"></drop>
<drop droplabel="What is this" dropvalue="1" selected="true"></drop>
<drop droplabel="What is that" dropvalue="2"></drop>
</item>
</element>


</formdata>

----------------------------------------------------------------------

Flex Code:


<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" backgroundGradientColors="white" backgroundDisabledColor="white" backgroundColor="white" layout="absolute" horizontalAlign="center" creationComplete="handleCreationComplete()" verticalScrollPolicy="auto" cachePolicy="off">

<mx:Script>
<![CDATA[
import mx.controls.Text;
import mx.containers.FormItem;
import mx.controls.Label;
import mx.controls.Button;
import mx.containers.ControlBar;
import mx.controls.TextInput;
import mx.controls.RadioButtonGroup;
import mx.controls.List;
import mx.controls.ComboBox;
import mx.controls.CheckBox;
import mx.controls.FormItemLabel;
import mx.controls.RadioButton;
import mx.controls.TextArea;
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.controls.ComboBox;
import mx.collections.ArrayCollection;
import mx.controls.DateField;
import mx.core.IUIComponent;
import mx.core.IUITextField;
import mx.utils.ObjectUtil;
import flash.utils.*;


private function handleCreationComplete():void
{

XMLService.send();

}

private function errorHandler(evt:FaultEvent):void
{
Alert.show("Error: " + evt.fault.message);
}

private function resultHandler(evt:ResultEvent):void
{

buildForm(new XML(evt.result));
}

private function buildForm(xml:XML):void
{
var lst:XMLList = xml.children();
var lsta:XMLList = xml.element.item.children();



for(var i:int = 0; i < lst.length(); i++)
{
var x:XMLList = lst[i].children();





for(var j:int = 0; j < x.length(); j++)
{
if(x[j].@inputtype == 'TextInput')
{
var frmItem:FormItem = new FormItem();
frmItem.direction = "vertical";


var tb:TextInput = new TextInput();
tb.text = x[j];
tb.id = x[j].@id;
tb.toolTip = 'Enter your Answer here';
frmItem.addChild(tb);

userInfoForm.addChild(frmItem);

}

else
{
// Support other form field types


if(x[j].@inputtype == 'ComboBox')
{


// Having problem with this nested loop.


for(var d:int = 0; d < lsta.length(); d++)

var p:XMLList = lsta[d].children();

for(var r:int = 0; r < p.length(); r++)



var frmItemCombo:FormItem = new FormItem();



var tg:ComboBox = new ComboBox();


tg.alpha = .5;
tg.text = p[r].@droplabel;
tg.width = 230;
tg.id = x[j].@id;
frmItemCombo.required = true;
tg.data = x[j].@label;


frmItemCombo.addChild(tg);

userInfoForm.addChild(frmItemCombo);



}
}
}
}


}
]]>
</mx:Script>
<mx:HTTPService fault="errorHandler(event)" id="XMLService" resultFormat="e4x" url="test/formdata_final_a.xml" result="resultHandler(event)" method="POST" />

<mx:Panel title="XML Driven Form -- Send Receive Data from SOA _JSP" height="90%" width="70%"
paddingTop="50" paddingBottom="10" paddingLeft="50" paddingRight="10" layout="vertical" horizontalAlign="left" verticalAlign="top" backgroundColor="#EEEFFD" borderColor="#E2E2E2" x="72.5" y="10">
<mx:Form id="userInfoForm" borderThickness="1" borderColor="#FCFAFA" borderStyle="solid" width="90%"/>
</mx:Panel>

</mx:Application>
revenekorb is offline   Reply With Quote
Old 09-27-2008, 06:51 AM   PM User | #2
Ricky158
Regular Coder

 
Join Date: Aug 2002
Location: New York
Posts: 152
Thanks: 12
Thanked 0 Times in 0 Posts
Ricky158 is an unknown quantity at this point
not exactly sure of how to fix this, but i can point you in the right direction.

the advantage of using XML in flex is the ease of formatting. there's no need to use for loops to iterate through every XML node -- this is a very inefficient way of working with XML and it is a waste of using e4x formatting. if you want to access a specific node in the XML structure, become familiar with the syntax for elements, attributes, and descendants (" . ", " .@ ", " .. ").
__________________
Ricky158 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:57 PM.


Advertisement
Log in to turn off these ads.