Flex: loading assets into external modules

So, I have a Flex project that loads a module using ModuleManager, not a module loader. The problem I encountered is that in order to load an external resource (for example, video or image), the path to load this resource must be relative to the swf module ... not relative to the swf that the module was loading.

Question: how can I load an asset into a loaded module using the path relative to the parent swf and not the swf module?


Arg! Thus, when going through the SWFLoader class, I found this piece of code in the private function 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 ( - , ...), , , , - "load about swf", SWFLoader , , , , swf, ... ?

+3
2

mx.core.Application, Application.application.url, - URL-.

URL- . URLUtil Flex URI as3corelib.

+2

this.url baseURL.

var urlParts:Array = this.url.split("/");
urlParts.pop();
baseURL = urlParts.join("/");
Alert.show(baseURL);

{baseURL + "/location/file.ext"} /location/file.ext

+1

Source: https://habr.com/ru/post/1697463/


All Articles