开发者

Get Loader name property through contentLoaderInfo handler

I want to pass a value through an image loading event, and my simple approach was setting a name into Loader object. But I didn't have success with that.

function loadAll()
{
    for(var i:uint = 0; i < len; i++)
    {
        var a:Loader = new Loader();
        a.name = "nome_" + i;
        a.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler, false, 0, t开发者_StackOverflowrue);                    

        a.load(new URLRequest(xml.Img[i]));

    }
}

function onCompleteHandler(e:Event)
{           
    trace("Loaded: " + e.target.name)   
}

e.target.name makes reference to contentLoaderInfo property. How can I access the loader object in my complete handler function?


The contentLoaderInfo is of type LoaderInfo and that has a read-only member variable called loader pointing to the Loader. So in your event handler you'd do

function onCompleteHandler(e:Event)
{           
    trace("Loaded: " + LoaderInfo(e.target).loader.name);   
}


Don't forget to check out the docs, they are very good: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/LoaderInfo.html

Answer: e.currentTarget.loader.name;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜