actionscript 3 - AS3, getting XML data from external URL. -
im trying work xml info :
http://flydata.avinor.no/xmlfeed.asp?timefrom=1&timeto=10&airport=ksu&direction=d%22
it contains official flydata airport. want name of airlines.
i null no matter try. if seek trace out length of tag 0.
this code ;
import flash.net.urlloader; import flash.net.urlrequest; import flash.events.event; var myxml:xml = new xml(); var xml_url:string = "http://flydata.avinor.no/xmlfeed.asp?timefrom=1&timeto=10&airport=ksu&direction=d%22"; var re:urlrequest = new urlrequest(xml_url); var ldr:urlloader = new urlloader(re); ldr.addeventlistener(event.complete, loaded); function loaded(e:event):void{ myxml = xml(ldr.data); trace("succses"); } var howlong:int = myxml.flight.length(); for(var count:int=0; count < howlong; count++){ var airline:string = myxml.flight[count].airline; } trace(airline)
the urlrequest
asynchronous operation for
loop executed before xml has been loaded. need move code iterates on returned xml finish handler:
import flash.net.urlloader; import flash.net.urlrequest; import flash.events.event; var myxml:xml = new xml(); var xml_url:string = "http://flydata.avinor.no/xmlfeed.asp?timefrom=1&timeto=10&airport=ksu&direction=d%22"; var re:urlrequest = new urlrequest(xml_url); var ldr:urlloader = new urlloader(re); ldr.addeventlistener(event.complete, loaded); function loaded(e:event):void { var howlong:int var airline:string; myxml = xml(ldr.data); howlong = myxml.flight.length(); trace("succses"); for(var count:int=0; count < howlong; count++){ airline = myxml.flight[count].airline; trace(airline); } }
xml actionscript-3 flash url
No comments:
Post a Comment