我有一个火花形式,看起来这个。我试图循环表单并将每个DropDownList的id推入一个数组。
我能够成功找出表单项的ID。但是我无法使用任何访问子项的方法获取DropDownList的ID,我使用的是Flex 3.我是新的Flex 4,经过一些阅读后我理解它是由于与spark架构相关的东西。
这是表格。
<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>
我可以像这样访问Form项目。 “设施”是表格的名称。
for (var i:int = 0 ;i <= facilities.numElements-1;i++)
{
var item:IVisualElementContainer = facilities.getElementAt(i) as IVisualElementContainer;
trace(item);
}
我尝试了这个链接http://www.igorcosta.org/?p=366并试图使用那里给出的类。
问题在于抛出了错误。 Flash构建器带我到该代码中的第二个函数中的第二个for循环,并显示在那里使用的item.numElements创建了问题。我尝试在我的代码中使用item.numElements(上面显示的那个,我跟踪了FormItem ids),它也没有用。有人有任何线索吗?
答案 0 :(得分:3)
在你的for循环中,facilities.getElementAt(i)将返回一个IVisualElement,不一定是一个IVisualElementContainer。
尝试使用:
var item:IVisualElement = facilities.getElementAt(i);
trace(item);
var itemContainer:IVisualElementContainer = item as as IVisualElementContainer;
if (itemContainer) {
trace(itemContainer.numElements);
}
这应该会给你你正在寻找的结果!