# URLLoader() -- event listener nightmare

**URL:** <https://forum.kirupa.com/t/urlloader-event-listener-nightmare/304746>\
**Category:** flash\
**Created:** [February 12, 2010, 10:49pm UTC](https://forum.kirupa.com/t/urlloader-event-listener-nightmare/304746 "2010-02-12T22:49:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lectersmeal](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/lectersmeal/32/1201_2.png) [@lectersmeal](https://forum.kirupa.com/u/lectersmeal)\
**Post date:** [February 12, 2010, 10:49pm UTC](https://forum.kirupa.com/t/urlloader-event-listener-nightmare/304746/1 "2010-02-12T22:49:46Z")

</div>

Sooo, I’m about to pull my hair out, and I hope that someone can help me.

I’m just trying to create a relatively simple application for my research, and I’m using URLLoader() to retrieve quite a lot of XML data.

**Project Overview (that’s relevant)**  
The XML data is a bunch of numbers that I need to display on a graph as soon as the page is loaded. So, it must be parsed and the values remapped to the height of the panel for display purposes.

**The mostly relevant code**  
(Side note about openXML(): This function either needs to return some data, or in my controller, I need to be able to make a call to a getData() function. But that’s not possible because there’s no guarantee that the XML data has been loaded yet.)

```auto

/* openXML() is being called by my controller, which is called by my application's initialize.*/

public function openXML():void {        
            var loader:URLLoader = new URLLoader();
            loader.addEventListener(Event.COMPLETE, loadXML);
            loader.load(new URLRequest(xmlURL));
        }
 
 private function loadXML(evt:Event):void {
            var xml:XML = new XML(evt.target.data);
            
            // setup all <R> (Reading) tags as an xml list
            xmlList = xml.R;
            
            for (var i:int=0;i<xmlList.length();i++) {
                value*=xmlList.v*;
            }    
            
            // each value will then need to be remapped to fit the panel
            // call the gsrController -- which will in turn draw all this stuff        
    }

```

So the problem is, I’m new to Flex. I would LOVE for a way for the openXML() file to be able to return the xmlList so that I can take all of that logic OUT of that event listener (If the logic stays in there, it will time out). But how could I accomplish that? It’s not like I can tell openXML() to wait on that event listener before it returns anything – haha.

When I was testing this stuff a few days ago, everything was working perfectly fine, but it was when I used data that corresponded to 40 minutes worth of video that it became a problem.

(And to provide a better overview of what I’m doing, the XML data is for drawing this line that the video player ticker is syncing up with as the video players…)

![](http://4228263637768846102-a-1802744773732722657-s-sites.googlegroups.com/site/erinacarroll/projects/videoplayer/gsrplayer2_hanson.jpg?attachauth=ANoY7crJAt2sjDo4y3pBGMyabnb0XFXucBd8TRPFR1N7b4_JuhGx8Q7a5kAEHYov5IhUjiOq33HI0hNqLd-tyAi7ojLYGFp1GLg_bNylQ07dAiY28xcFeOM8B8dJCm2bhfvxlx6Q0t5FkrjtMeo4YFR-VPuArUHuiQnFwbT_XLUrYrVSif2zvqBzgsk1MLf9ZirS_hVCBgnBSDHOQ-wla-7RR-4CWDUCe-UpOnmn9sZdKMeucsV4DxY%3D&attredirects=0)

Anyway, I would really appreciate some advice from more seasoned ActionScript programmers. :bu:
