2008-09-24 64 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