apache-flex - 弹性 : Loading assets into externally loaded modules

标签 apache-flex flash actionscript-3

所以,我有一个 Flex 项目,它使用 ModuleManager 加载模块 - 而不是模块加载器。我遇到的问题是,要加载外部资源(如视频或图像),加载该资源的路径必须相对于模块 swf...而不是相对于加载模块的 swf。

问题是 - 如何使用相对于父 swf(而不是模块 swf)的路径将资源加载到已加载的模块中?

<小时/>

嗯!因此,在深入研究 SWFLoader 类时,我在私有(private)函数 loadContent 中发现了这段代码:

    // make relative paths relative to the SWF loading it, not the top-level SWF
    if (!(url.indexOf(":") > -1 || url.indexOf("/") == 0 || url.indexOf("\\") == 0))
    {
         var rootURL:String;
         if (SystemManagerGlobals.bootstrapLoaderInfoURL != null && SystemManagerGlobals.bootstrapLoaderInfoURL != "")
              rootURL = SystemManagerGlobals.bootstrapLoaderInfoURL;
         else if (root)
              rootURL = LoaderUtil.normalizeURL(root.loaderInfo);
         else if (systemManager)
              rootURL = LoaderUtil.normalizeURL(DisplayObject(systemManager).loaderInfo);

              if (rootURL)
              {
                   var lastIndex:int = Math.max(rootURL.lastIndexOf("\\"), rootURL.lastIndexOf("/"));
                    if (lastIndex != -1)
                         url = rootURL.substr(0, lastIndex + 1) + url;
               }
          }
}

很明显,Adobe 已经付出了额外的努力来使图像加载到实际的 swf 中,而不是顶级的 swf 中(没有标志可供选择……),所以我想我应该提交一个功能请求来拥有某种“相对于 swf 的加载”标志,直接编辑 SWFLoader,或者也许我应该拥有与单个 swf 相关的所有内容,而不是顶层...有什么建议吗?

最佳答案

您可以导入mx.core.Application,然后使用Application.application.url获取模块中主机应用程序的路径并将其用作构建 URL 的基础。

有关处理 URL 的帮助,请参阅 the URLUtil class in the standard Flex librariesthe URI class in the as3corelib project .

关于apache-flex - 弹性 : Loading assets into externally loaded modules,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/127598/

相关文章:

actionscript-3 - AS3 - addEventListener 参数的使用

actionscript-3 - Spark 标签截断问题

css - 音量条的自定义皮肤

apache-flex - 如何将货币格式化程序放入 Flex 数据网格列中?

flash - 如何在 HTML 中嵌入 SWF?

actionscript-3 - AS3 : Accessing custom class public functions from a MovieClip on a timeline

flash - 如何绘制正弦线图?

apache-flex - Flex 4 - 当容器的子级依赖于状态时如何循环它们

css - 如何在模块中使用主应用程序样式而不嵌入 flex 4 版本中的运行时样式加载

c++ - 在网络浏览器中运行 C/C++ 代码?