Search code examples
flashactionscript-3event-handlingloader

how to get back the loader after Event.COMPLETE with my code? (as3, flash)


can you please tell me how you get the loader back after a Event.COMPLETE?

i tried the example from the doc, i tried different stuff, but i always have a "error to convert Loader in LoaderInfo, or in myImport..."

this does not work : TypeError: Error #1034:

function loader_my_import(){
    var loader = new Loader();
    var url:URLRequest = new URLRequest("myImport.swf");
    loader.load(url);
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, complete_imgs);
}

function complete_imgs(e:Event){
      loader_IMGS = Loader(e.target.content);
}

loader_IMGS being already declared at the beginning of the class.

Thanks


Solution

  • It doesn't work because e.target is a LoaderInfo object not a loader (you add the event listener to the contentLoaderInfo ). From the LoaderInfo you can then get the originate loader

    So it should be :

    function complete_imgs(e:Event){
     var li:LoaderInfo = LoaderInfo(e.target)
     var loader:Loader = li.loader
    }