actionscript 3 - AS3 - Problems with Functions that Return Values of Variables from Loaded Data -
i trying make blitting engine, , part giving me hard time. trying make external class of xml parsing file texture packer spits out. made class in utilities package called xmlparserblit.as
i hoping able instantiate , call 1 function it's job, this:
var _xmlparser:xmlparserblit = new xmlparserblit(); _blitdataary = _xmlparser.getaryfromblitxmldata("blit_test_4.xml");
however, seems it's not going easy. function inside of xmlparserblit class has event listener triggers function happen when loading complete. seems flash keeps going on through function, , trace("finished array: " + _xmldataary); returns blank array. there way me wait complete listener finished? or maybe can responsibility on returning value getaryfromblitxmldata on onxmlloaded?
i stumped, , learning how beat problem open mind how tackle similar problems. thanks.
public function getaryfromblitxmldata(xmlpath:string):array { _xmldataary = [] _xmlpath = xmlpath; _testxml = new xml(); _testxmlrequest = new urlrequest(_xmlpath); _testxmlloader = new urlloader(); _testxmlloader.addeventlistener(event.complete, onxmlloaded); _testxmlloader.load(_testxmlrequest); trace("finished array: " + _xmldataary); return _xmldataary; } protected function onxmlloaded(event:event):void { _loadedxml = new xml(event.target.data); var thesprites:xmllist = _loadedxml..sprite each ( var _rectsprite:xml in thesprites) { //-------------------------------------- // string manipulations here //-------------------------------------- } var _rectangle:rectangle = new rectangle(_xvalue, _yvalue, _widthvalue, _heightvalue); var miniary:array = [_rectangle, _xoffsetvalue, _yoffsetvalue] _xmldataary.push(miniary); //* want return _xmldataary getaryfromblitxmldata function } }
onxmlloaded
won't trigger until after load function finishes asynchronously. best bet make getaryfromblitxmldata
not return value, , handle _xmldataarray
inside of onxmlloaded
Comments
Post a Comment