我有选择从XML文件中获取值的框。程序加载时,它会自动显示XML文件中第一个值的信息。我还需要它在选择框中突出显示该值。
这是它最初加载时的样子
由于它是自动加载这些图像,我希望在选择框中选择该类型("按颜色" - >" Barnwood")
(我继承的代码有很多文件,所以我只会显示我认为相关的代码。我对Flex的知识非常有限......)
private function onCatReceived(e:ResultEvent):void
{
var cats:Array= new Array();
loadItems(Globals.compRoot+catDataProvider.lastResult.elements("category")[0].catid);
for each(var cat:XML in catDataProvider.lastResult.elements("category"))
{
if (cats[cat.parent.toString()])
{
cats[cat.parent.toString()].addItem(cat);
}
else
{
cats[cat.parent.toString()]= new ArrayCollection();
cats[cat.parent.toString()].addItem(cat);
}
}
for (var ct:String in cats)
{
var cnv:Canvas= new Canvas();
var dataSort:SortField= new SortField("name",true);
var nameSort:Sort= new Sort();
nameSort.fields=[dataSort];
var source:ArrayCollection=cats[ct];
source.sort=nameSort;
source.refresh();
cnv.label=ct;
cnv.horizontalScrollPolicy="off";
cnv.verticalScrollPolicy="off";
var lst:List= new List();
lst.width=166;
lst.height=115;
lst.labelField="name";
lst.styleName="ControllerList";
lst.addEventListener(ListEvent.CHANGE,changeCat);
lst.dataProvider=cats[ct];
Alert.show("ct: " + ct);
cnv.addChild(lst);
acc.addChild(cnv);
}
//Maybe add it here??
//mouldingList.items.selectedIndex = 0;
var cnv:Canvas = acc.getChildAt(0) as Canvas;
var lst:List = cnv.getChildAt(1) as List;
Alert.show(lst.toString());
Alert.show(lst.selectedItem.toString());
}
答案 0 :(得分:0)
我浏览了Accordion中的每个Canvas,如果它与“By Color”匹配,则设置List的Accordion的selectedIndex。
private function onCatReceived(e:ResultEvent):void
{
var cats:Array= new Array();
loadItems(Globals.compRoot+catDataProvider.lastResult.elements("category")[0].catid);
for each(var cat:XML in catDataProvider.lastResult.elements("category"))
{
if (cats[cat.parent.toString()])
{
cats[cat.parent.toString()].addItem(cat);
}
else
{
cats[cat.parent.toString()]= new ArrayCollection();
cats[cat.parent.toString()].addItem(cat);
}
}
for (var ct:String in cats)
{
var cnv:Canvas= new Canvas();
var dataSort:SortField= new SortField("name",true);
var nameSort:Sort= new Sort();
nameSort.fields=[dataSort];
var source:ArrayCollection=cats[ct];
source.sort=nameSort;
source.refresh();
cnv.label=ct;
cnv.horizontalScrollPolicy="off";
cnv.verticalScrollPolicy="off";
var lst:List= new List();
lst.width=166;
lst.height=115;
lst.labelField="name";
lst.styleName="ControllerList";
lst.addEventListener(ListEvent.CHANGE,changeCat);
lst.dataProvider=cats[ct];
//Alert.show("ct: " + ct);
cnv.addChild(lst);
acc.addChild(cnv);
switch (ct)
{
case "By Color":
acc.addChildAt(cnv, 0);
break;
case "By Material":
acc.addChildAt(cnv, 1);
break;
case "By Style":
acc.addChildAt(cnv, 2);
break;
default:
acc.addChild(cnv);
}
//acc.addChildAt(cnv, 0);
}
//Set the selected item to be the 0th item
for each (var o:Object in acc.getChildren())
{
if (o is Canvas)
{
var c:Canvas = o as Canvas;
if ("By Color" == c.label)
{
c.setFocus(); //does this work?
c.drawFocus(true); //does this work?
acc.selectedIndex = 0; //does this work?
for each (var o2:Object in o.getChildren())
{
if (o2 is List)
{
var l:List = o2 as List;
l.selectedIndex = 0;
}
}
}
}
}