views:

322

answers:

1

I am using multiple asynchronous air.URLLoader objects, and would like the events fired to be aware of the urlloader's "myId". The objects i am downloading have ids per se, so i'd like to know in my event listener callback function from which download id the progress/finished/error event came.

code:

# 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);
}

The addEventListener callback function is per framework limited to just the event as parameter. The events come also from air, i don't know how to alter them (inject the myId i.e.).

I also tried jQuery.extend() with a simple value/getter/setter object on the air.URLLoader, but no success.

event dump:

{
  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
}
A: 

After some research it seems that the AIR classes just won't let you extend them in any way.

I worked around this issue by using a queue, sacrificing the asynchronous part. For downloading purposes this shouldn't be that bad, because before the bandwidth would have been splitted.

Karsten

related questions