我正在尝试创建一个可以显示 XML 选项列表的应用程序。然后,当单击一个选项时,从不同的 XML 加载数据以显示他们选择的选项,即 [j]。
我在这里的代码在通过循环后只进入最后一个变量,所以无论我点击哪个选项,它都会进入最后一个选项的数据。它也只删除原始按钮的最后一个子按钮。
有谁知道我怎样才能让它进入正确的页面?
import flash.events.Event;
import flash.text.TextField;
var xmlLoader:URLLoader = new URLLoader();
var xmlReq:URLRequest = new URLRequest("http://praxis2.cit.ie/~patrickhallihan/DynamicContent/autumn/classxml.php");
xmlLoader.load(xmlReq);
xmlLoader.addEventListener(Event.COMPLETE, getClasses);
function getClasses(e:Event):void
{
var xmlobject:XML = new XML(e.target.data);
var classlist:XMLList = xmlobject.classgroup;
var classArray:Array = new Array();
for (var i:int = 0; i<classlist.length(); i++)
{
var classname:String = xmlobject.classgroup.classname[i];
var classtxt:TextField = new TextField();
classtxt.width = 70;
classtxt.height = 20;
classtxt.border = true;
classtxt.borderColor = 0x000000;
classtxt.background = true;
classtxt.backgroundColor = 0x888888;
classtxt.textColor = 0xFFFFFF;
classtxt.text = "" + classname;
addChild (classtxt);
classArray[i] = classtxt;
}
for (var j:int = 0; j<classlist.length(); j++)
{
classArray[j].y = 40*j;
classArray[j].x = 125;
classArray[j].addEventListener(MouseEvent.CLICK, gotoSchedule);
function gotoSchedule(event:MouseEvent):void
{
removeChild (classtxt);
var xmlLoader1:URLLoader = new URLLoader();
var xmlReq1:URLRequest = new URLRequest("http://praxis2.cit.ie/~patrickhallihan/DynamicContent/autumn/getschedule.php?id="+ j);
xmlLoader1.load(xmlReq1);
xmlLoader1.addEventListener(Event.COMPLETE, getExams);
function getExams(e:Event):void
{
trace (xmlLoader1.data);
var examtxt:TextField = new TextField();
examtxt.width = 260;
examtxt.height = 400;
examtxt.y = 30;
examtxt.x = 30;
examtxt.border = true;
examtxt.borderColor = 0x000000;
examtxt.background = true;
examtxt.backgroundColor = 0x888888;
examtxt.textColor = 0xFFFFFF;
examtxt.text = (xmlLoader1.data);
addChild (examtxt);
}
}
}
}