我正在尝试读取XML文件并在简单的列表组件或控制台中显示其内容。 问题是事件监听器是在无限循环中触发的。
代码:
var myXML:XML;
var myLoader:URLLoader = new URLLoader();
myLoader.addEventListener(Event.COMPLETE, processXML);
myLoader.load(new URLRequest("/songs/songs.xml"));
function processXML(e:Event):void {
myXML = new XML(e.target.data);
trace(myXML.*);
}
xml文件:
<?xml version="1.0" encoding="utf-8"?>
<Songs>
<Song>Sleep Away.mp3</Song>
<Song>Kalimba.mp3</Song>
</Songs>
输出:
<Song>Sleep Away.mp3</Song>
<Song>Kalimba.mp3</Song>
<Song>Sleep Away.mp3</Song>
<Song>Kalimba.mp3</Song>
<Song>Sleep Away.mp3</Song>
<Song>Kalimba.mp3</Song>
<Song>Sleep Away.mp3</Song>
<Song>Kalimba.mp3</Song>
<Song>Sleep Away.mp3</Song>
<Song>Kalimba.mp3</Song>
<Song>Sleep Away.mp3</Song>
<Song>Kalimba.mp3</Song>
<Song>Sleep Away.mp3</Song>
<Song>Kalimba.mp3</Song>
<Song>Sleep Away.mp3</Song>
<Song>Kalimba.mp3</Song>
<Song>Sleep Away.mp3</Song>
<Song>Kalimba.mp3</Song>
<Song>Sleep Away.mp3</Song>
<Song>Kalimba.mp3</Song>
<Song>Sleep Away.mp3</Song>
<Song>Kalimba.mp3</Song>
<Song>Sleep Away.mp3</Song>
<Song>Kalimba.mp3</Song>
<Song>Sleep Away.mp3</Song>
<Song>Kalimba.mp3</Song>
<Song>Sleep Away.mp3</Song>
<Song>Kalimba.mp3</Song>
<Song>Sleep Away.mp3</Song>
<Song>Kalimba.mp3</Song>
<Song>Sleep Away.mp3</Song>
<Song>Kalimba.mp3</Song>
<Song>Sleep Away.mp3</Song>
<Song>Kalimba.mp3</Song>
<Song>Sleep Away.mp3</Song>
<Song>Kalimba.mp3</Song>
<Song>Sleep Away.mp3</Song>
<Song>Kalimba.mp3</Song>
<Song>Sleep Away.mp3</Song>
<Song>Kalimba.mp3</Song>
<Song>Sleep Away.mp3</Song>
<Song>Kalimba.mp3</Song>
<Song>Sleep Away.mp3</Song>
<Song>Kalimba.mp3</Song>
<Song>Sleep Away.mp3</Song>
<Song>Kalimba.mp3</Song>
<Song>Sleep Away.mp3</Song>
<Song>Kalimba.mp3</Song>
<Song>Sleep Away.mp3</Song>
<Song>Kalimba.mp3</Song>
<Song>Sleep Away.mp3</Song>
<Song>Kalimba.mp3</Song>
<Song>Sleep Away.mp3</Song>
....
答案 0 :(得分:1)
首先,这只是在IDE的时间轴上吗?如果是,您是否需要添加stop()
?
其次,您可以在COMPLETE
事件发布后立即从加载程序中删除侦听器。
function processXML(e:Event):void {
myLoader.removeEventListener(Event.COMPLETE, processXML);
myXML = new XML(e.target.data);
trace(myXML.*);
}