AS3/ XML Loop through a group of parsed xml paths and update them in the same textfields.

With the following code I have several dynamic textfields that have an unchangeable xml path.  I what to be able to loop to the next node section of the xml and load them into the same textfields upon an update function.  Please look at mu code and see if this makes sense...

As you can see in the code I have several sections being updated, but what I would like to do is simplify this so that no matter how many xml nades are produced they will be updated into the same textfields (upon another function probably going to be a timer).

Also the: Flights.flight_mc.schedTime_txt.text = newTimeStr; paths will need to be updated as well, but they are unique as they have different variables associated with them.  I hope I havent made this too difficult to understand.  If so I would be glad to elaborate...  Just let me knoe what you need to know.

As always any help is greatly appreciated!
 
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("http://www.flightstats.com/go/rss/flightStatusByAirport.do?guid=34b64945a69b9cac:28fe44e:122319722a2:-1e56&airportCode=TUL&airportQueryType=0&sortField=0&codeshareDisplay=1"));
function LoadXML(e:Event):void {
	trace("LoadXML");
	xmlData = new XML(e.target.data);
	ParseContent(xmlData);
}
function ParseContent(contentInput:XML):void {
	Refresh();
	namespace someNamespace= "http://rss.flightstats.com/ns/rss/1.0"
	var timeStr:String = contentInput.channel.item.someNamespace::FlightHistory[0].@DepartureDate;
	var dt:String = timeStr.split(" ")[0];
	var hr:String = timeStr.split(" ")[1].split(":")[0];
	var mn:String = timeStr.split(" ")[1].split(":")[1];
	var ampm:String = "A";
	var i:uint;
	for (i=0; i<myArray.length; i++) {
		// code
	}
	if (parseInt(hr) > 12) {
		ampm = "P";
		hr = (parseInt(hr) - 12).toString();
	}
	var newTimeStr:String = hr + ":" + mn + ampm;
	trace("newTimeStr = " + newTimeStr);// newTimeStr = 2009-06-30 3:00 PM
	var timeStr2:String = contentInput.channel.item.someNamespace::FlightHistory[0].@EstimatedGateDepartureDate;
	var dt2:String = timeStr2.split(" ")[0];
	var hr2:String = timeStr2.split(" ")[1].split(":")[0];
	var mn2:String = timeStr2.split(" ")[1].split(":")[1];
	var ampm2:String = "A";
 
	if (parseInt(hr2) > 12) {
		ampm2 = "P";
		hr2 = (parseInt(hr2) - 12).toString();
	}
	var newTimeStr2:String = hr + ":" + mn + ampm;
	trace("newTimeStr2 = " + newTimeStr2);
	
	Flights.flight_mc.airline_txt.text = contentInput.channel.item.someNamespace::FlightHistory[0].someNamespace::Airline.@Name;
	Flights.flight_mc.location_txt.text = contentInput.channel.item.someNamespace::FlightHistory[0].someNamespace::Destination.@City;
	Flights.flight_mc.gate_txt.text = contentInput.channel.item.someNamespace::FlightHistory[0].@DepartureGate;
	Flights.flight_mc.schedTime_txt.text = contentInput.channel.item.someNamespace::FlightHistory[0].@DepartureDate;
	Flights.flight_mc.schedTime_txt.text = newTimeStr;
	Flights.flight_mc.estTime_txt.text = contentInput.channel.item.someNamespace::FlightHistory[0].@EstimatedGateDepartureDate;
	Flights.flight_mc.estTime_txt.text = newTimeStr2;
	Flights.flight_mc.status_txt.text = contentInput.channel.item.someNamespace::FlightHistory[0].@Status;
 
	Flights.flight_mc2.airline_txt.text = contentInput.channel.item.someNamespace::FlightHistory[1].someNamespace::Airline.@Name;
	Flights.flight_mc2.location_txt.text = contentInput.channel.item.someNamespace::FlightHistory[1].someNamespace::Destination.@City;
	Flights.flight_mc2.gate_txt.text = contentInput.channel.item.someNamespace::FlightHistory[1].@DepartureGate;
	Flights.flight_mc2.schedTime_txt.text = contentInput.channel.item.someNamespace::FlightHistory[1].@DepartureDate;
	Flights.flight_mc2.estTime_txt.text = contentInput.channel.item.someNamespace::FlightHistory[1].@EstimatedGateDepartureDate;
	Flights.flight_mc2.status_txt.text = contentInput.channel.item.someNamespace::FlightHistory[1].@Status;
 
	Flights.flight_mc3.airline_txt.text = contentInput.channel.item.someNamespace::FlightHistory[2].someNamespace::Airline.@Name;
	Flights.flight_mc3.location_txt.text = contentInput.channel.item.someNamespace::FlightHistory[2].someNamespace::Destination.@City;
	Flights.flight_mc3.gate_txt.text = contentInput.channel.item.someNamespace::FlightHistory[2].@DepartureGate;
	Flights.flight_mc3.schedTime_txt.text = contentInput.channel.item.someNamespace::FlightHistory[2].@DepartureDate;
	Flights.flight_mc3.estTime_txt.text = contentInput.channel.item.someNamespace::FlightHistory[2].@EstimatedGateDepartureDate;
	Flights.flight_mc3.status_txt.text = contentInput.channel.item.someNamespace::FlightHistory[2].@Status;
	
        Flights.flight_mc4.airline_txt.text = contentInput.channel.item.someNamespace::FlightHistory[3].someNamespace::Airline.@Name;
	Flights.flight_mc4.location_txt.text = contentInput.channel.item.someNamespace::FlightHistory[3].someNamespace::Destination.@City;
	Flights.flight_mc4.gate_txt.text = contentInput.channel.item.someNamespace::FlightHistory[3].@DepartureGate;
	Flights.flight_mc4.schedTime_txt.text = contentInput.channel.item.someNamespace::FlightHistory[3].@DepartureDate;
	Flights.flight_mc4.estTime_txt.text = contentInput.channel.item.someNamespace::FlightHistory[3].@EstimatedGateDepartureDate;
	Flights.flight_mc4.status_txt.text = contentInput.channel.item.someNamespace::FlightHistory[3].@Status;
	
        Flights.flight_mc5.airline_txt.text = contentInput.channel.item.someNamespace::FlightHistory[4].someNamespace::Airline.@Name;
	Flights.flight_mc5.location_txt.text = contentInput.channel.item.someNamespace::FlightHistory[4].someNamespace::Destination.@City;
	Flights.flight_mc5.gate_txt.text = contentInput.channel.item.someNamespace::FlightHistory[4].@DepartureGate;
	Flights.flight_mc5.schedTime_txt.text = contentInput.channel.item.someNamespace::FlightHistory[4].@DepartureDate;
	Flights.flight_mc5.estTime_txt.text = contentInput.channel.item.someNamespace::FlightHistory[4].@EstimatedGateDepartureDate;
	Flights.flight_mc5.status_txt.text = contentInput.channel.item.someNamespace::FlightHistory[4].@Status;
}

Open in new window

cubical38Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cubical38Author Commented:
Okay here is what I have thus far which is working, sort of...  The problem:  once the first 5 nodes have been loaded, how do I increment through to the next five and so on and so on...  Also along with that how do I increment through my newTimeStr variable?  Hope this makes it a clearer on what I am trying to accomplish...

so to recap:  there are five movieclips each containing 6 dynamic textfields.  Each movieclip will load in the next specified xml node and its corresponding text.  Once I reach the end of those 5 nodes how do I increment it so that on a function such as click to next it loads the next 5 nodes into the same movieclip textfields?

Thanks Again, and any direction is helpful!


       
 
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
var xmlList:XMLList = new XMLList();
var index:Number = 0;
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("http://www.flightstats.com/go/rss/flightStatusByAirport.do?guid=34b64945a69b9cac:28fe44e:122319722a2:-1e56&airportCode=TUL&airportQueryType=0&sortField=0&codeshareDisplay=1"));
function LoadXML(e:Event):void {
	trace("LoadXML");
	xmlData = new XML(e.target.data);
	xmlList = xmlData.children();
	trace(xmlList);
	ParseContent(xmlData);
}
 
function ParseContent(contentInput:XML):void {
	Refresh();
	namespace someNamespace= "http://rss.flightstats.com/ns/rss/1.0"
 
	var timeStr:String = contentInput.channel.item.someNamespace::FlightHistory[index].@DepartureDate;
	var dt:String = timeStr.split(" ")[0];
	var hr:String = timeStr.split(" ")[1].split(":")[0];
	var mn:String = timeStr.split(" ")[1].split(":")[1];
	var ampm:String = "A";
 
	if (parseInt(hr) > 12) {
		ampm = "P";
		hr = (parseInt(hr) - 12).toString();
	}
	var newTimeStr:String = hr + ":" + mn + ampm;
	trace("newTimeStr = " + newTimeStr);// newTimeStr = 2009-06-30 3:00 PM
	var timeStr2:String = contentInput.channel.item.someNamespace::FlightHistory[index].@EstimatedGateDepartureDate;
	
	var dt2:String = timeStr2.split(" ")[0];
	var hr2:String = timeStr2.split(" ")[1].split(":")[0];
	var mn2:String = timeStr2.split(" ")[1].split(":")[1];
	var ampm2:String = "A";
 
	if (parseInt(hr2) > 12) {
		ampm2 = "P";
		hr2 = (parseInt(hr2) - 12).toString();
	}
	var newTimeStr2:String = hr + ":" + mn + ampm;
	trace("newTimeStr2 = " + newTimeStr2);
 
	Flights.flight_mc.airline_txt.text = contentInput.channel.item.someNamespace::FlightHistory[index].someNamespace::Airline.@Name;
	Flights.flight_mc.location_txt.text = contentInput.channel.item.someNamespace::FlightHistory[index].someNamespace::Destination.@City;
	Flights.flight_mc.gate_txt.text = contentInput.channel.item.someNamespace::FlightHistory[index].@DepartureGate;
	Flights.flight_mc.schedTime_txt.text = contentInput.channel.item.someNamespace::FlightHistory[index].@DepartureDate;
	Flights.flight_mc.schedTime_txt.text = newTimeStr;
//not sure how to increment this variable
	Flights.flight_mc.estTime_txt.text = contentInput.channel.item.someNamespace::FlightHistory[index].@EstimatedGateDepartureDate;
	Flights.flight_mc.estTime_txt.text = newTimeStr2;
	Flights.flight_mc.status_txt.text = contentInput.channel.item.someNamespace::FlightHistory[index].@Status;
	index ++;
	Flights.flight_mc2.airline_txt.text = contentInput.channel.item.someNamespace::FlightHistory[index].someNamespace::Airline.@Name;
	Flights.flight_mc2.location_txt.text = contentInput.channel.item.someNamespace::FlightHistory[index].someNamespace::Destination.@City;
	Flights.flight_mc2.gate_txt.text = contentInput.channel.item.someNamespace::FlightHistory[index].@DepartureGate;
	Flights.flight_mc2.schedTime_txt.text = contentInput.channel.item.someNamespace::FlightHistory[index].@DepartureDate;
	Flights.flight_mc.schedTime_txt.text = newTimeStr;
	Flights.flight_mc2.estTime_txt.text = contentInput.channel.item.someNamespace::FlightHistory[index].@EstimatedGateDepartureDate;
	Flights.flight_mc.estTime_txt.text = newTimeStr2;
	Flights.flight_mc2.status_txt.text = contentInput.channel.item.someNamespace::FlightHistory[index].@Status;
	index ++;
	Flights.flight_mc3.airline_txt.text = contentInput.channel.item.someNamespace::FlightHistory[index].someNamespace::Airline.@Name;
	Flights.flight_mc3.location_txt.text = contentInput.channel.item.someNamespace::FlightHistory[index].someNamespace::Destination.@City;
	Flights.flight_mc3.gate_txt.text = contentInput.channel.item.someNamespace::FlightHistory[index].@DepartureGate;
	Flights.flight_mc3.schedTime_txt.text = contentInput.channel.item.someNamespace::FlightHistory[index].@DepartureDate;
	Flights.flight_mc.schedTime_txt.text = newTimeStr;
	Flights.flight_mc3.estTime_txt.text = contentInput.channel.item.someNamespace::FlightHistory[index].@EstimatedGateDepartureDate;
	Flights.flight_mc.schedTime_txt.text = newTimeStr2;
	Flights.flight_mc3.status_txt.text = contentInput.channel.item.someNamespace::FlightHistory[index].@Status;
	index ++;
	Flights.flight_mc4.airline_txt.text = contentInput.channel.item.someNamespace::FlightHistory[index].someNamespace::Airline.@Name;
	Flights.flight_mc4.location_txt.text = contentInput.channel.item.someNamespace::FlightHistory[index].someNamespace::Destination.@City;
	Flights.flight_mc4.gate_txt.text = contentInput.channel.item.someNamespace::FlightHistory[index].@DepartureGate;
	Flights.flight_mc4.schedTime_txt.text = contentInput.channel.item.someNamespace::FlightHistory[index].@DepartureDate;
	Flights.flight_mc.schedTime_txt.text = newTimeStr;
	Flights.flight_mc4.estTime_txt.text = contentInput.channel.item.someNamespace::FlightHistory[index].@EstimatedGateDepartureDate;
	Flights.flight_mc.schedTime_txt.text = newTimeStr2;
	Flights.flight_mc4.status_txt.text = contentInput.channel.item.someNamespace::FlightHistory[index].@Status;
	index ++;
	Flights.flight_mc5.airline_txt.text = contentInput.channel.item.someNamespace::FlightHistory[index].someNamespace::Airline.@Name;
	Flights.flight_mc5.location_txt.text = contentInput.channel.item.someNamespace::FlightHistory[index].someNamespace::Destination.@City;
	Flights.flight_mc5.gate_txt.text = contentInput.channel.item.someNamespace::FlightHistory[index].@DepartureGate;
	Flights.flight_mc5.schedTime_txt.text = contentInput.channel.item.someNamespace::FlightHistory[index].@DepartureDate;
	Flights.flight_mc.schedTime_txt.text = newTimeStr;
	Flights.flight_mc5.estTime_txt.text = contentInput.channel.item.someNamespace::FlightHistory[index].@EstimatedGateDepartureDate;
	Flights.flight_mc.schedTime_txt.text = newTimeStr2;
	Flights.flight_mc5.status_txt.text = contentInput.channel.item.someNamespace::FlightHistory[index].@Status;
//at this point I need to upon a function or timer reload these same textfields with the next set of xml nodes
}

Open in new window

0
rascalpantsCommented:
well, this looks like a great place to introduce a for loop, and populate the movieclip text fields with it...

and get everything out of the XML event handler... it should be in a seperate function.

also, if you are going to use a sequentially numbered movieclip structure, then don't start with a generic clip name...

so..  "flight_mc"  should actually be "flight_mc1"

change that and make this easier on everyone...   :)


rp


//
var clips:Array = new Array();
clips.push( {clip: Flights.flight_mc1} );
clips.push( {clip: Flights.flight_mc2} );
clips.push( {clip: Flights.flight_mc3} );
clips.push( {clip: Flights.flight_mc4} );
clips.push( {clip: Flights.flight_mc5} );
//
var currIndex:int = 0;
//
 
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
var xmlList:XMLList = new XMLList();
var index:Number = 0;
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("http://www.flightstats.com/go/rss/flightStatusByAirport.do?guid=34b64945a69b9cac:28fe44e:122319722a2:-1e56&airportCode=TUL&airportQueryType=0&sortField=0&codeshareDisplay=1"));
function LoadXML(e:Event):void {
	trace("LoadXML");
	xmlData = new XML(e.target.data);
	xmlList = xmlData.children();
	trace(xmlList);
	ParseContent(xmlData);
}
 
function ParseContent(contentInput:XML):void {
	Refresh();
	namespace someNamespace= "http://rss.flightstats.com/ns/rss/1.0"
 
	var timeStr:String = contentInput.channel.item.someNamespace::FlightHistory[index].@DepartureDate;
	var dt:String = timeStr.split(" ")[0];
	var hr:String = timeStr.split(" ")[1].split(":")[0];
	var mn:String = timeStr.split(" ")[1].split(":")[1];
	var ampm:String = "A";
 
	if (parseInt(hr) > 12) {
		ampm = "P";
		hr = (parseInt(hr) - 12).toString();
	}
	var newTimeStr:String = hr + ":" + mn + ampm;
	trace("newTimeStr = " + newTimeStr);// newTimeStr = 2009-06-30 3:00 PM
	var timeStr2:String = contentInput.channel.item.someNamespace::FlightHistory[index].@EstimatedGateDepartureDate;
	
	var dt2:String = timeStr2.split(" ")[0];
	var hr2:String = timeStr2.split(" ")[1].split(":")[0];
	var mn2:String = timeStr2.split(" ")[1].split(":")[1];
	var ampm2:String = "A";
 
	if (parseInt(hr2) > 12) {
		ampm2 = "P";
		hr2 = (parseInt(hr2) - 12).toString();
	}
	var newTimeStr2:String = hr + ":" + mn + ampm;
	trace("newTimeStr2 = " + newTimeStr2);
     
    updateMovieClips( currIndex ); 
}
 
function updateMovieClips( currIndex:int ):void
{
  var len:int = clips.length;
  for(var i:int = 0; i < len; i++)
  {
    var theData:XML = contentInput.channel.item.someNamespace::FlightHistory[ currIndex ];
    
    clips[i].airline_txt.text = theData.someNamespace::Airline.@Name;
    clips[i].location_txt.text = theData.someNamespace::Destination.@City;
    clips[i].gate_txt.text = theData.@DepartureGate;
    clips[i].schedTime_txt.text = theData.@DepartureDate;
    clips[i].schedTime_txt.text = newTimeStr;
    clips[i].estTime_txt.text = theData.@EstimatedGateDepartureDate;
    clips[i].estTime_txt.text = newTimeStr2;
    clips[i].status_txt.text = theData.@Status;
  }
 
  currIndex++;
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rascalpantsCommented:
the above code might not compile properly, but I thought I would get you started before I left on holiday til monday...

rp
0
cubical38Author Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.