Export and import swflite? (html5)

I’m trying to load remote swf files into my openFL application. Targeting flash, I was able to download a byte array with URLLoader and create the swf object using ‘new format.SWF(byte_array)’

That isn’t available when targeting html5 (or any non-flash target, I think…), so I think the next best thing is to add another step to my asset creation process where after exporting a .swf from Animate I add the .swf to an empty project and let OpenFL process it into a swflite asset. Afterwards, find a way to export the swflite and then find a way to import those processed assets into my other application.

Does that sound doable? The goal is to have a compiled html5 project I can set up and leave as is, and then have a mutable folder of .swf (or swflite) files I can load in and view.

This is close to working

First, we need some minor tweaks to make sure that the relative addresses work. Second, I’d like to have some command (such as openfl process library.swf) for generating SWFLite from a SWF, without having to attach it to a project and build that way.

It works with Loader pointing to a *.json, but I’m wondering if there’s some way we can fuse the generated files together a bit more, somehow.

Such as:

 - library.json
 - assets

Still thinking, but a folder convention may make it easier to move them around

I’ve made progress on this today

With the latest OpenFL and Lime development builds, it should be possible to pre-process a SWF, and then load at runtime.

openfl process library.swf
openfl process library.swf output/path
openfl process library.swf path/to/output.bundle

If you openfl rebuild tools with the latest source, the openfl command should have a process tool, which generates a “*.bundle” file, which contains all the files needed for SWFLite use later.

The optional extra parameter should take an output directory or an output bundle name. If the bundle name is omitted, it will match the name of the SWF by default.

At runtime, the following should now work for loading the main timeline:

var loader = new Loader ();
loader.contentLoaderInfo.addEventListener (IOErrorEvent.IO_ERROR, function (e) trace (e));
loader.load (new URLRequest ("path/to/library.bundle"));
addChild (loader);

You should also be able to load it more manually:

AssetManifest.loadFromFile ("path/to/library.bundle/library.json").onComplete (function (manifest) {
	var library = AssetLibrary.fromManifest (manifest);
	library.load ().onComplete (function (_) {
		var clip = library.getMovieClip ("NyanCatAnimation");
		addChild (clip);
	}).onError (function (e) {
		trace (e);

I think the next step is to hook up the Loader class (with the SWF content) with a custom implementation of ApplicationDomain so we can get named symbols from the Loader as well :slight_smile:

1 Like