我正在使用多个异步air.urlloader对象,并希望激发的事件能够知道urlloader的“myid”。
我下载的对象本身都有ID,所以我想知道在我的事件侦听器回调函数中,下载ID的进度/完成/错误事件来自哪个函数。
代码:
# loader
addonLoader = new air.URLLoader();
//addonLoader.myId = my_id; <- does not work:
// error: Failed: Error #1056: Cannot create property my_id on flash.net.URLLoader.
addonLoader.dataFormat = air.URLLoaderDataFormat.BINARY;
addonLoader.addEventListener(air.IOErrorEvent.IO_ERROR, myDownloadListenerError);
addonLoader.addEventListener(air.ProgressEvent.PROGRESS, myDownloadListenerProgress);
addonLoader.addEventListener(air.Event.COMPLETE, myDownloadListenerFinished);
addonLoader.load(addonRequest);
# listener callback
function myDownloadListenerFinished(event)
{
air.trace('finished: '+event.target.myId);
// i need the addonLoader.myId here
// i have access to the caller, but i cannot add my own property/value to it
air.Introspector.Console.dump(event);
}
每个框架的addEventListener回调函数仅限于事件作为参数。事件也来自空气,我不知道如何改变它们(注入myid,即)。
我还尝试在air.urlloader上使用一个简单的value/getter/setter对象jquery.extend(),但没有成功。
事件转储:
{
bubbles=false
bytesLoaded=262144
bytesTotal=10933705
cancelable=false
clone=[function]
{
length=0
}
currentTarget=[object URLLoader]
{
addEventListener=[function]
bytesLoaded=262144
bytesTotal=10933705
close=[function]
data=undefined
dataFormat=binary
dispatchEvent=[function]
hasEventListener=[function]
load=[function]
removeEventListener=[function]
toString=[function]
willTrigger=[function]
}
eventPhase=2
formatToString=[function]
{
length=1
}
isDefaultPrevented=[function]
{
length=0
}
preventDefault=[function]
{
length=0
}
stopImmediatePropagation=[function]
{
length=0
}
stopPropagation=[function]
{
length=0
}
target=[object URLLoader]
{
addEventListener=[function]
bytesLoaded=262144
bytesTotal=10933705
close=[function]
data=undefined
dataFormat=binary
dispatchEvent=[function]
hasEventListener=[function]
load=[function]
removeEventListener=[function]
toString=[function]
willTrigger=[function]
}
toString=[function]
{
length=0
}
type=progress
}