How to defer SWF library loading until after preloading step on HTML 5

I have this in my project.xml:

Despite the preload=false setting, all the assets in the assets.swf are preloaded at the start of the app on the HTML 5 target. I’d wish to be able to decide when to load those assets as I don’t want them holding up the app initialization. Is this not doable on the HTML 5 target? If not, I’d like to take a crack at implementing the feature, but I don’t know exactly where to start, what haxe library and files to look at.

You might look at “tools/Tools.hx” in the SWF haxelib.

Right now, all the dependency assets are pushed into the asset list. This makes it part of the preload process on HTML5. With Assets.loadLibrary it may be possible to load a SWF library later, at runtime, but it would require some work to make things work like that. It would not work with generated class names (like new MySWFSymbol) until its been loaded, but that’s an understandable restriction?

Okay cool, I’ll start there then.

Regarding the restriction, that’s completely fine, it makes perfect sense. As long as I can defer loading of SWF assets in an HTML 5 app until later, it would help a big deal with the sort of web apps I’m building that require fast as possible initialization.

Again, thanks for the tip.

I think the key is that we want to load these assets with our library somehow – then if we preload="true" on our SWF library, it preloads along with everything else, but if we do not, then we will manually load our library. We’re sort of “cheating” at the moment by pushing these things into the default asset library rather than loading them separately in the SWF libraries

Right, so I need to remove them from the DefaultAssetManager. I also have to remove them from the ApplicationMain class because I’m looking at its create() method and it looks like is where the individual asset paths are declared and passed on to the Preloader for loading. So the SWF library Tools.hx would be where the assets are added to those 2 classes?

So if preload=“true”, the current functionality is fine? It’s just preload=“false” when the target is set to HTML 5 which is not yet implemented right?

Yeah, so the SWF tools (you can compile it using haxe compile.hxml in that tools directory) push in the assets to the standard asset system. This has a lot of added benefit to standard file copying/embedding/preloading behavior, but falls flat when we want to load it separately from the rest. It’s a little bit of a tricky problem.

I added a trace() line to Tools.hx and then ran “haxe build.xml” and it worked. So the run.n file for each haxe library included in the project.xml is executed automatically whenever “openfl build myproject” is run? It seems like it, at least with the SWF library.

So as long as I can use Assets.loadLibrary(“assets”) and Assets.getMovieClip(“assets:icon”) to load my swf assets at a later time, I’m fine with foregoing those benefits.

What’s the embed property in the “lime.project.Library” class for?

Okay, so the tools have the idea of a “library handler”, that knows how to process libraries. This is the mechanism used by the SWF library.

So “embed” is a three-state value, true, false or null. embed=true means that an asset file is pushed into the executable on native, into the SWF on Flash, and preloaded on HTML5 (it is not put in the JS file at the moment)

Undefined, embed=null allows each platform to choose its default. SWF defaults to embedding, native does not, HTML5 defaults to preloading. embed=false means it copies files but does not embed. This means on SWF and HTML5 that Assets.get* does not work, only Assets.load*

Awesome, thanks for the pointers, it really helped me navigate this whole lime + swf process chain. I think I got it working in HTML5.

All I had to do was modify lime.Assets.loadLibrary() to async load the assets.json file if getText(libraries/assets.json) returns null, using the lime.app.Preloader class so that the json and dat files can be found by the DefaultAssetLibrary.getText(). And then remove the “#if swflite_preloader” line from SWFLiteLibrary.load() to allow it to load the Bitmaps, if any, in the assets.dat file. And finally add preload=false and embed=false to the element in the project.xml file.

It seems to work on initial testing so I think this is good enough for my own purposes.

1 Like

Cool, ill try and find if I can make this more formaly supported – I definitely understand the use case :slight_smile:

Just checking in on this thread to see if the runtime swf loading has been implemented. I’d love to make use of this as well! Is there documentation / sample use case somewhere to compare it to the normal swf approach?

In Project.hxp I have the following line of code:
libraries.push(new Library(“assets/assets.swf”, “assetsLib”, “swf”, true));
In Main.hx I’m Assets.loadLibrary(“assetsLib”, swfAssetsLoaded);
If embed=true, It works well in browsers Chrome, Mozilla and IE but not load in Safari.
If embed=false, is loaded on all browsers but Assets.loadLibrary(“assetsLib”, swfAssetsLoaded) not working.

Thank you

Hello

How did you do that? I'm new in openfl and not have much idea how to modify function lime.Assets.loadLibrary( ). If you give emded = false, not working but I need to be false for many reasons. Please help me with a solution. Thank you!

Sorry for my English