所以,我有Flex项目使用ModuleManager加载模块 - 而不是模块加载器。我遇到的问题是加载外部资产(如视频或图像)加载该资产的路径必须相对于模块swf ...而不是相对于加载模块的swf。
问题是 - 如何使用相对于父swf的路径将资产加载到已加载的模块中,而不是模块swf?
精氨酸!因此,在挖掘SWFLoader类时,我在私有函数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的所有内容而不是顶级...任何建议?
答案 0 :(得分:2)
您可以导入mx.core.Application
,然后使用Application.application.url获取模块中主机应用程序的路径,并将其用作构建网址的基础。
有关处理网址的帮助,请参阅the URLUtil class in the standard Flex libraries和the URI class in the as3corelib project。
答案 1 :(得分:1)
您可以在模块中使用this.url并将其用作baseURL。
var urlParts:Array = this.url.split("/");
urlParts.pop();
baseURL = urlParts.join("/");
Alert.show(baseURL);
并使用{baseURL + "/location/file.ext"}
代替/location/file.ext