2008-09-24 62 views
3

因此,我有使用ModuleManager加载模块的Flex项目 - 而不是模块加载器。我遇到的问题是要加载外部资源(如视频或图像),加载资源的路径必须相对于模块swf ...而不是相对于加载模块的swf。Flex:将资产加载到外部加载的模块中

问题是 - 我如何使用相对于父SWF而不是模块SWF的路径将资产加载到加载的模块中?


Arg!因此,在通过的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加载”标志,直接编辑SWFLoader,或者我应该拥有与单个swf相关的所有内容,不是顶级...有什么建议?

回答

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