首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AIR javascript类扩展- air.URLLoader和静态事件

AIR javascript类扩展- air.URLLoader和静态事件
EN

Stack Overflow用户
提问于 2009-07-03 08:12:34
回答 1查看 640关注 0票数 0

我使用了多个异步air.URLLoader对象,并希望触发的事件能够识别the加载器的"myId“。我正在下载的对象本身就有id,所以我想在我的事件侦听器回调函数中知道哪个下载id是从哪个下载id/完成/错误事件来的。

代码:

代码语言:javascript
复制
# 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(),但没有成功。

事件转储:

代码语言:javascript
复制
{
  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
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2009-07-21 12:18:46

经过一些研究,似乎AIR类不会让你以任何方式扩展它们。

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1078307

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档