所以,我有一个 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 libraries和 the URI class in the as3corelib project .
关于apache-flex - 弹性 : Loading assets into externally loaded modules,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/127598/