Using embedded SWF assets [Windows]

I had this problem for a while, but this time I would really like to solve it. Basically, if you embed a SWF library (bundle) - it wouldn’t be accessible anymore.

The SWF libraries are being generated via the openfl process mySWF.swf command. That would by default give me a mySWF.bundle directory with my assets.

In the projects.xml file I could then include the library:

<assets path="assets/layout.bundle" rename="layout" embed="false" />

In my project, I would have to first load the library and then be able to use it. It’s wildly convenient to use it this way because I get access to generated classes that I could then use with all the auto-completion.

The problem starts when I try to set the tag embed=true. At this point the generated bundle becomes a part of the EXE file, and you can see the assets in the asset-list: Assets.list().toString() would give you a whole list of assets.

But now there’s no known way to access any of the assets. Trying to use any of set methods from the Assets class would tell me that the asset does not exist.

An interesting side note is that SWF assets aren’t listed within any AssetType category:

		trace( "all", Assets.list().toString() ); // [symbols/1.png,symbols/9.png,swflite.bin,symbols/6.png,symbols/15.png,fonts/NotoSansJP-Regular.otf]
		trace( "bin", Assets.list(AssetType.BINARY).toString() ); // [fonts/NotoSansJP-Regular.otf]
		trace( "font", Assets.list(AssetType.FONT).toString() ); // [fonts/NotoSansJP-Regular.otf]
		trace( "img", Assets.list(AssetType.IMAGE).toString() ); //[]
		trace( "mcs", Assets.list(AssetType.MOVIE_CLIP).toString() ); //[]
		trace( "music", Assets.list(AssetType.MUSIC).toString() ); //[]
		trace( "sound", Assets.list(AssetType.SOUND).toString() ); //[]
		trace( "text", Assets.list(AssetType.TEXT).toString() ); //[]
		trace( "template", Assets.list(AssetType.TEMPLATE).toString() ); //[]

FYI, the font in this example is added via <assets path="assets/fonts" rename="fonts" embed="true"/> and is not a part of the main library.

Is there a way use generated bundles without referring to the generated=true tag and loading SWFs? The reason I want to use bundles is because it’s really nice for auto-completion, especially with nested assets and using SWFs would often bug out IDEs and make them stop auto-completion throughout the whole project.

Lime added an AssetBundle class which should be able to extract a zipped library at runtime, this can then be used as a library at runtime

I think it would be good if this path (runtime not build time) would be used for bundles so they are just a flat binary zip file and don’t require so much special handling in the command line tools

Asset Bundle sounds cool, but:

  1. There’s no sample on how to use it anywhere. Searched on lime-samples and openfl-samples etc.
  2. This doesn’t address the main problem of embedding resources. Although I’ve tried to simply ZIP my SWF file, use Haxe --resources flag to add it, use AssetBundles to load my ZIP, and openfl.Assets to load the SWF extracted from the said ZIP as a library. My code didn’t work, but it potentially could.

If I could fix my code below I think I could use embedded resources for future builds if I really wanted to keep everything in a single EXE file (or at least some more sensitive data files):

class Main extends Sprite 
{

	public function new() 
	{
		super();

		 // testLib is a "test.zip" file embedded via
         // <haxeflag name="-resource assets/[email protected]" /> in project.xml
		var bytes = haxe.Resource.getBytes("testLib");
		
		var ab = AssetBundle.loadFromBytes(bytes).onComplete( (ab:AssetBundle) ->
		{
			for ( p in ab.paths)
			{
				trace( p ); // output: test.swf
				Assets.loadLibrary( p ).onComplete( (al:AssetLibrary) ->
				{
					var t = Assets.getMovieClip("TestMC");
					trace(t == null);
					addChild(t);
				}).onError( (d) -> { // ERROR: There is no asset library with an ID of "test.swf"
					trace( Std.string(d) );
				});
			}
			
			for ( key in ab.data.keys())
			{
				trace( key, ab.data[key]); // output: test.swf,CWS☼8
			}
		});
	}

}

@singmajesty Can you please write a code snippet here in this post? I’ll make a pull-request to lime-samples over the weekend myself. I really don’t know how AssetBundles are intended to be used together with openfl.Assets to register a library, so I need your help.