I’m having a small problem here.
I’m attaching an array of objects to the stage, each with a x and y values from an external xml. I have 2 values for the y property.
So when I attach the objects to the stage y property takes the first y values. When I want to change the y value to the send y value I am only accessing the last value in the list. What am I doing wrong?
///the external xml file
<?xml version=“1.0” encoding=“utf-8”?>
<Tickers>
<Ticker>
<lat>100 </lat>
<lon> 100</lon>
<lon2>150</lon2>
</Ticker>
<Ticker>
<lat>100 </lat>
<lon> 150</lon>
<lon2>200</lon2>
</Ticker>
<Ticker>
<lat>100 </lat>
<lon> 200</lon>
<lon2>250</lon2>
</Ticker>
</Tickers>
///the code
var tickerList1:XMLList;
var tickerList2:XMLList;
var tickerList3:XMLList;
var data:XML;
var tickerIndex:int=0;
var box:redBox;
var nodex:int;
var nodey:int;
var nodey2:int;
var i:int;
var loader:URLLoader = new URLLoader();
loader.load(new URLRequest(“events.xml”));
loader.addEventListener(Event.COMPLETE, LoadXML);
function LoadXML(event:Event):void {
var data:XML=new XML(loader.data);
tickerList1=data.Ticker.lat;
tickerList2=data.Ticker.lon;
tickerList3=data.Ticker.lon2;
for (i = 0; i < tickerList1.length(); i++) {
nodex=tickerList1[ID=i];
nodey=tickerList2[ID=i];
nodey2=tickerList3[ID=i];
redbox=attachRedBoxes();
}
}
function attachRedBoxes() {
box = new redBox ();
box.x=nodex;
box.y=nodey;
box.ID=i;
addChild(box);
}
///the button to change the y property
btn.addEventListener(MouseEvent.MOUSE_DOWN,change_ypos);
function change_ypos(e:MouseEvent):void {
for (i=numChildren-1; i>=0; i–) {
getChildAt(i).y=nodey2;
}