# Using URLLoader in Class

**URL:** <https://forum.kirupa.com/t/using-urlloader-in-class/275476>\
**Category:** flash\
**Created:** [November 14, 2008, 4:47am UTC](https://forum.kirupa.com/t/using-urlloader-in-class/275476 "2008-11-14T04:47:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![boysetsfire](https://avatars.discourse-cdn.com/v4/letter/b/71c47a/32.png) [@boysetsfire](https://forum.kirupa.com/u/boysetsfire)\
**Post date:** [November 14, 2008, 4:47am UTC](https://forum.kirupa.com/t/using-urlloader-in-class/275476/1 "2008-11-14T04:47:51Z")

</div>

First off i feel like i shouldnt have to import flash.events.Event or flash.events.IOErrorEvent because shouldnt those be apart of URLLoader? I get an error if i dont include them both. Second when I instantiate var song:Songs = new Songs(file.xml); it never gets inside the onComplete function or the onIOError. I tried hard coding the xml file name into the loader but it still didnt go into the onComplete function. Any thoughts?

```auto

package {
    import flash.events.Event;
    import flash.events.IOErrorEvent;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    
    public class Songs{
        var track:Number;
        var songXML:XML;
        var songList:XMLList;
        var loader:URLLoader = new URLLoader();
        
        public function Songs(file){
        loader.addEventListener( Event.COMPLETE, onComplete,false, 0,true);
        loader.addEventListener( IOErrorEvent.IO_ERROR, onIOError, false, 0, true);
        loader.load( new URLRequest(file));
        }
        
        private function onComplete(evt:Event):void {
            try{
                songXML = new XML(evt.target.data);
                songList = songXML.song;
                trace(songList);
                loader.removeEventListener(Event.COMPLETE, onComplete);
                loader.removeEventListener(IOErrorEvent.IO_ERROR, onIOError);
            }catch(err:Error){
                trace("problem");
            }
        }
    
        private function onIOError(evt:IOErrorEvent):void{
            trace("Error");
        }
}
}

```
