Quoting via forms in Flex 4
I have a spark that looks like this. I am trying to loop through the form and push the id of each individual DropDownList into an array.
I can track the IDs of the form elements successfully. But I cannot get the DropDownList id using any of the methods that I have used to access children is Flex 3. I am new Flex 4 and after some reading I figured it out due to something related to spark architecture ...
This is the form.
<s:Form id="facilities" x="51" y="32" width="595" height="402">
<s:FormHeading label="SWOT ANALYSIS FORMAT FOR PLOT PURCHASE" fontSize="15">
</s:FormHeading>
<s:FormItem id = "petrolPumpsFormItem" required="true" width="464" label="Petrol Pumps:">
<s:DropDownList id = "petrolPumps" width="220" prompt="Select distance from the plot" labelField="distance" >
<s:dataProvider>
<s:ArrayCollection>
<fx:Object distance="1-3 km" mark="100"/>
<fx:Object distance="3-6 km" mark="90"/>
<fx:Object distance="6-9 km" mark="80"/>
<fx:Object distance="9-12 km" mark="70"/>
<fx:Object distance="12-15 km" mark="60"/>
<fx:Object distance="15-18 km" mark="50"/>
</s:ArrayCollection>
</s:dataProvider>
</s:DropDownList>
</s:FormItem>
<s:FormItem id="filmTheatreFormItem" required="true" width="464" label="Film Theatre:">
<s:DropDownList id="filmTheatre" width="220" prompt="Select distance from the plot" labelField="distance" >
<s:dataProvider>
<s:ArrayCollection>
<fx:Object distance="1-3 km" mark="100"/>
<fx:Object distance="3-6 km" mark="90"/>
<fx:Object distance="6-9 km" mark="80"/>
<fx:Object distance="9-12 km" mark="70"/>
<fx:Object distance="12-15 km" mark="60"/>
<fx:Object distance="15-18 km" mark="50"/>
</s:ArrayCollection>
</s:dataProvider>
</s:DropDownList>
</s:FormItem>
<s:FormItem id= "atmFormItem" required="true" width="464" label="ATM:">
<s:DropDownList id= "atm" width="220" prompt="Select distance from the plot" labelField="distance" >
<s:dataProvider>
<s:ArrayCollection>
<fx:Object distance="1-3 km" mark="100"/>
<fx:Object distance="3-6 km" mark="90"/>
<fx:Object distance="6-9 km" mark="80"/>
<fx:Object distance="9-12 km" mark="70"/>
<fx:Object distance="12-15 km" mark="60"/>
<fx:Object distance="15-18 km" mark="50"/>
</s:ArrayCollection>
</s:dataProvider>
</s:DropDownList>
</s:FormItem>
</s:Form>
I could access a form element like this. "Objects" is the name of the form.
for (var i:int = 0 ;i <= facilities.numElements-1;i++)
{
var item:IVisualElementContainer = facilities.getElementAt(i) as IVisualElementContainer;
trace(item);
}
I tried this link http://www.igorcosta.org/?p=366 and tried to use the class provided there.
The problem was that an error was thrown. The Flash builder took me to a second loop in the second function inside this code and showed that the item.numElements used there was causing the problem. I tried using item.numElements inside my code (the one shown above that I was tracking FormItem IDs with) and it also didn't work. Anyone prompted?
source to share
Within the for loop, facility.getElementAt (i) will return an IVisualElement, not necessarily an IVisualElementContainer.
Try the following:
var item:IVisualElement = facilities.getElementAt(i);
trace(item);
var itemContainer:IVisualElementContainer = item as as IVisualElementContainer;
if (itemContainer) {
trace(itemContainer.numElements);
}
This will give you the results you are looking for!
source to share