我花了數小時試圖弄清楚這一點......任何幫助將不勝感激!如何將孩子添加到flex 4中的手風琴兒童?
我有一個讀取生成手風琴編程容器的ArrayCollection:
<s:ArrayCollection id="_ac_ps">
<fx:Object label="Block and lot" data="_blocklot" searchType="districtblocklot" info="" />
<fx:Object label="Address" data="_address" searchType="singletxtstring" info=""/>
<fx:Object label="Owner name" data="_owner" searchType="singletxtstring" info=""/>
<fx:Object label="Advanced data mining" data="_advanced" searchType="advancedmining" info=""/>
</s:ArrayCollection>
而且我這是怎麼產生的手風琴孩子:
for (var num1:int = 0; num1 <= _ac_ps.length - 1; num1++)
{
navContent = new NavigatorContent();
navContent.percentWidth = 100;
navContent.percentHeight = 100;
navContent.label = _ac_ps[num1].label;
navContent.id = ""+_ac_ps[num1].data;
navContent.name = ""+_ac_ps[num1].data;
////(""+navContent.id);
_searchAccordion.addChild(navContent);
}
這工作得很好。現在我想要做的是基於手風琴中導航器內容的ID,添加孩子。例如,我想將一個Label類型的子元素添加到id爲「_blocklot」的navigatorContent中,但將一個textInput元素添加到id爲「_address」的navigatorContent對象中。
private function loadSearchControls():void
{
var accordionChildren:Array = _searchAccordion.getChildren();
for each(var currentnavContent:NavigatorContent in accordionChildren)
{
Alert.show (""+currentnavContent.id, "currentnavContent.id");
if (currentnavContent.id == "_blocklot")
{
try{
var _label:Label = new Label();
_label.text = "come on now!!!!!!";
//SO HOW DO I CAPTURE THE ID SO THAT I CAN ADD THIS LABEL AS A CHILD???
//_searchAccordion._blocklot.addChild(_label); does not work
}
catch(errorObj:Error)
{
Alert.show("nope");
}
}
else if (currentnavContent.id == "_address")
{
Alert.show("bbb");
}
}
您還可以在這裏查看我的回答:http://stackoverflow.com/questions/7885478/loading-components-dynamically-in-flex-4/7896593#7896593 – kbgn