AS3: return an array from an event listener?

I have an event listener applied to xml loading and it is currently tracking the values โ€‹โ€‹it captures, which is good, but what I want is to return an array for me. I have the creation and return of an array from "LoadXML" (it returns an array), but I cannot get this to work with an event listener.

The event listener works fine with the LoadXML function, but I have no idea how to get the returned array to use, this is an example of how my event listener works:

xmlLoader.addEventListener(Event.COMPLETE, LoadXML());

and my guess about how I will take an array (this will not work):

var rArray:Array = xmlLoader.addEventListener(Event.COMPLETE, LoadXML());

so instead i tried the following:

xmlLoader.addEventListener(Event.COMPLETE, function():Array{
    var rData:Array = LoadXML(datahere);
    return rData;
}

but itโ€™s not worth it either.

So: How to return an array from eventlistener? Thank you

+3
3

, , . , , .

, , - , . , , Event . :

xmlLoader.addEventListener(Event.COMPLETE, handleLoadComplete/*Note: No brackets, this is a reference*/);

//will be called at a later time, not instantly.
function handleLoadComplete(e:Event):void {
    var xml:XML = xmlLoader.data as XML;
    //do what ever you want this the XML...
}

, .

!

+2

( xml LoadXML())?

var rArray:Array;
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);

private function LoadXML(event:Event=null):void {
    // set this.rArray in here...
}
+1

, returnArray , convertXML, , . Flash .

, , pastebin:

  • loadInformation()
    • var returnedArray:Array = loadinformation("http://website.com/xml.xml");
  • Flash, , xmlLoader , LoadXML()
    • xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
  • XML
    • xmlLoader.load(new URLRequest(xmlurl));
  • Flash, LoadXML() ( convertXML())
    • function LoadXML(e:Event):void {...}
  • loadInformation()
  • Flash , XML
  • XML . Flash LoadXML(), .
    • , LoadXML() Flash, loadInformation().
  • LoadXML() XML .

, - clownbaby: returnArray LoadXML.

var returnedArray:Array;

loadinformation("http://website.com/xml.xml");

function loadinformation(xmlurl:String):Array{
    var xmlLoader:URLLoader = new URLLoader();
    var xmlData:XML = new XML();
    xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
    xmlLoader.load(new URLRequest(xmlurl));
}

function LoadXML(e:Event):void {
    xmlData = new XML(e.target.data);
    returnedArray = convertXML(xmlData);
}

function convertXML(xml):Array{
    // Does some stuff with the XML and returns an array
    return rArray;
}
0

Source: https://habr.com/ru/post/1731713/


All Articles