Assets.loadLibrary without <library path="path/to/your.swf" /> into project.xml

Hi!

I have many swf files and I want to load some of them by Assets.loadLibrary().

Before of that I load .bundles dynamically but now I don’t know how it works. I could load them including the library path into project.xml but is tedious and I don’t want to have to do it every time I add a new swf file.

Are there any way to load swf without into project.xml?

Thanks!!

This should be possible if you run openfl process first:

openfl process test.swf

This should generate a “test.bundle” directory.

We are currently working on a newer SWF conversion format that outputs to a ZIP file instead.

1. Including a .bundle in your assets directory

If you drop a *.bundle directory in your assets directory, it should be possible to use Assets.loadLibrary with the path to the bundle, like this:

Assets.loadLibrary("assets/test.bundle").onComplete(function(_)
{
    var clip = Assets.getMovieClip("assets/test.bundle:MyMovieClip");
    addChild(clip);
});

2. Including a .bundle separately

You should be able to load a *.bundle from an arbitrary location at runtime using one of two methods

var loader = new Loader();
loader.load(new URLRequest("path/to/test.bundle"));
addChild(loader);

Similar to how Flash instantiates content when using a Loader, this will instantiate the main timeline of the target library once it is loaded. I believe we might also register it with Assets so that you can reference other resources

var clip = Assets.getMovieClip("path/to/test.bundle:MyMovieClip");

The other method is to use openfl.utils.AssetLibrary and to load it that way. Once loaded you can register with openfl.utils.Assets if you like for convenience.

AssetLibrary.loadFromFile("path/to/test.bundle").onComplete(function(library)
{
    var clip = library.getMovieClip("MyMovieClip");
    // or
    Assets.registerLibrary("test", library);
    var clip = Assets.getMovieClip("test:MyMovieClip");
    addChild(clip);
});

Thanks for quick asnwer!

I have a project and I load .bundle perfectly 1 week ago but I try to do this way because I upload openfl and lime to the last version and suddendly when I load .bundles in runtime the console returns this warning “[lime.utils.AssetLibrary] WARNING: Could not find library type: openfl._internal.swf.SWFLiteLibrary” and nothing is drawn :frowning:

I try running openfl process over the SWFs again but the warning persists. Do you know whats is wrong?

Thanks again!!

Is this the development version from GIT or the latest release on Haxelib?

There has been a fair amount of dust lately on GIT but I think it is smoothing out (but you will need to openfl rebuild tools after pulling the latest to build the changes for SWF libraries)

I’ve fixed it… removing the Chrome cache :sweat_smile: The browser was getting old .bundle files!!

Sorry and thanks for all!!

1 Like