[英]Flash AS3 loading XML into listbox
I am able to load my XML file into flash and trace results. 我能够将XML文件加载到Flash中并跟踪结果。 Want to populate listbox with information from xml file.
想要用xml文件中的信息填充列表框。
Structure of xml file: xml文件的结构:
<eBorders>
<item>
<thumb>borderTh/blank_th.jpg</thumb>
<file>border/blank.jpg</file>
</item>
<item>
<thumb>borderTh/border1_th.jpg</thumb>
<file>border/border1.jpg</file>
</item>
</eBorders>
AS3 code: AS3代码:
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("xml/borders.xml"));
var dp:DataProvider = new DataProvider("borders.xml");
border_lb.dataProvider = dp;
border_lb.iconField = "iconSource";
border_lb.rowHeight = 45;
function processXML(e:Event):void {
myXML = new XML(e.target.data);
for(var i:int=0;i<myXML.*.length(); i++){
dp.addItem({iconSource:myXML.item.thumb.[i]});
}
}
Code is producing error I can't find. 代码产生了我找不到的错误。
Thank you in advance for any help you might offer. 预先感谢您提供的任何帮助。
Annie 安妮
I think there is some items missing from your explanatiion that would help clarify your problem. 我认为您的说明中缺少一些可以帮助您解决问题的项目。
For example, the processXML function is being triggered by an event (e:Event) but that event isn't shown. 例如,processXML函数由事件(e:Event)触发,但未显示该事件。
Also, it's unclear what exactly border_lb is (ie is it an Object, a Dictionary?). 另外,还不清楚border_lb到底是什么(即,它是一个对象,还是一个字典?)。
That being said, I think the key line to change is: 话虽如此,我认为改变的关键是:
iconSource:myXML.item.thumb.[i] iconSource:myXML.item.thumb。[i]
to 至
iconSource:myXML.item.thumb.text()[i] iconSource:myXML.item.thumb.text()[i]
OR 要么
iconSource:myXML.item.thumb[i] // minus the period iconSource:myXML.item.thumb [i] //减去句点
See example: 参见示例:
import fl.data.DataProvider;
var myXML:XML = <eBorders>
<item>
<thumb>borderTh/blank_th.jpg</thumb>
<file>border/blank.jpg</file>
</item>
<item>
<thumb>borderTh/border1_th.jpg</thumb>
<file>border/border1.jpg</file>
</item>
</eBorders>;
var dp:DataProvider = new DataProvider();
var border_lb:Dictionary = new Dictionary();
border_lb.dataProvider = dp;
border_lb.iconField = "iconSource";
border_lb.rowHeight = 45;
function processXML():void {
for(var i:int=0;i < myXML.*.length(); i++){
trace(myXML.item.thumb.text()[i]);
dp.addItem({iconSource:myXML.item.thumb.text()[i]});
}
}
processXML();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.