我使用了多个异步air.URLLoader对象,并希望触发的事件能够识别the加载器的"myId“。我正在下载的对象本身就有id,所以我想在我的事件侦听器回调函数中知道哪个下载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回调函数仅限于将事件作为参数。这些事件也来自air,我不知道如何改变它们(例如注入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
}发布于 2009-07-21 12:18:46
经过一些研究,似乎AIR类不会让你以任何方式扩展它们。
我通过使用队列解决了这个问题,牺牲了异步部分。出于下载的目的,这应该不会那么糟糕,因为在此之前,带宽会被分割。
https://stackoverflow.com/questions/1078307
复制相似问题