Values of my Array are undefined outside of my function -


i started learning as3 , flash , i've got question. can see in code below, i've created array out of objects got xml file. within function "xmlread" have no problems tracing, or using values of array or ever. problem want use array outside of function "xmlread" , not within. whenever try access values of "monthparams" outside of function, says array "undefined". how can use array created?

import flash.display.loader; import flash.net.urlrequest; import flash.events.event; import flash.events.dataevent;  var monthparams= new array; var month= new object(); var myloader:urlloader = new urlloader();  myloader.load(new urlrequest("parameter.xml")); myloader.addeventlistener(event.complete, xmlread);  var actualmonth= 0;  function xmlread(e:event){     var myxml:xml=new xml(e.target.data);     myxml.ignorewhitespace=true;      (var xmli:int=0; xmli < myxml.monat.length(); xmli++) {         month.number=myxml.month[xmli].number.text();         month.namen=myxml.month[xmli].namen.text();         month.mid=myxml.month[xmli].mid.text();         month.devi=myxml.month[xmli].devi.text();         month.incli=myxml.month[xmli].incli.text();         month.korr=myxml.month[xmli].korr.text();         monthparams.push(month);     }     trace (monthparams[actualmonth].mid);  // works fine }  trace (monthparams[actualmonth].mid);      // doesn't work 

it's because xml load asynchronous operation, code isn't. means first start load xml, , after (on last line of code) try trace value. but xml still not loaded. then, @ point, xml gets loaded, , xmlread executed, trace there prints populated array.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -