0
我正在使用多個異步air.URLLoader對象,並希望觸發的事件知道urlloader的「myId」。 我下載的對象本身有ID,所以我想知道在我的事件監聽器回調函數中從哪個下載ID進度/完成/錯誤事件來。AIR javascript類擴展 - air.URLLoader和靜態事件
代碼:
# 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即)。
我也嘗試過使用jQuery.extend()方法在air.URLLoader上創建一個簡單的值/ getter/setter對象,但沒有成功。
事件轉儲:
{
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
}