【问题标题】:AIR javascript class extension - air.URLLoader and static eventsAIR javascript 类扩展 - air.URLLoader 和静态事件
【发布时间】:2009-07-03 08:12:34
【问题描述】:

我正在使用多个异步 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 即)。

我还尝试了 jQuery.extend() 与 air.URLLoader 上的简单 value/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
}

【问题讨论】:

    标签: javascript jquery oop inheritance air


    【解决方案1】:

    经过一些研究,AIR 类似乎不允许您以任何方式扩展它们。

    我通过使用队列解决了这个问题,牺牲了异步部分。出于下载目的,这应该不是那么糟糕,因为在带宽被分割之前。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-19
      • 1970-01-01
      • 1970-01-01
      • 2011-05-12
      • 2020-07-22
      • 2018-06-18
      相关资源
      最近更新 更多