I want to port some as3 code(to target html5), where I download a lot of external swf files via Loader and then access some classes from them using:
var c:Class = loaderInfo.applicationDomain.getDefinition(name) as Class;
var instance:Sprite = new c();
https://www.openfl.org/learn/haxelib/tutorials/using-swf-assets/ explains only how to embed swf files to access classes inside, does it mean that it’s the only possible way to do it?
UPDATE: Tested both approaches.
- My old as3 code still works in flash target, but for some reason in html5 target I can’t load .swfs (IOError). Perhaps html5 target simply does not support this approach?
- Then I tried to embed my swfs(around 60) via tags in project.xml, but after this project does not complile at all: Fatal error in gc Too many heap sections pops up. Is it because of the amount of swfs files and packing all assets in one fat swf will help? Or is it because of the assets amount and packing everything in one swf won’t help?
We do not currently support loading SWF files at runtime, but we do support a format we call “SWFLite” which is meant to decrease the processing time required to use the assets – the format is not perfect, but is transparent and can be improved.
When and where does “Fatal error in gc Too many heap sections” appear? What version of Haxe and Neko are you using?
There could be an issue in our SWF -> SWFLite converter tool – perhaps it is retaining too much memory when batch processing.
You can also try
openfl process path/to/your.swf to convert the SWF files into “*.bundle” directories. These can be used at runtime using
var loader = new Loader ();
loader.contentLoaderInfo.addEventListener (Event.COMPLETE, onComplete);
loader.load (new URLRequest ("path/to/your.bundle"));
AssetLibrary.loadFromFile ("path/to/your.bundle").onComplete (onComplete);
Bear in mind that our SWF asset support does not support scripting, shape tweens, “new” motion tweens, sound and some other features. I would recommend compiling any classes you need at runtime into the same project at first.
Thanks for quick response! I’ll try bundle approach tomorrow.
Fatal error in gc appears when I simply try to build project. For testing I tried to leave only 1 out of 60 embedded swf and it works fine. I am using Haxe 3.4.7, Neko 2.1.0
You can try
openfl build html5 -verbose and it may give us more information about when the error occurs – my guess is that it is while processing the SWF
Yep, your guess is correct. It occurs while processing swfs.
openfl process path/to/your.swf on one of my .swf file which has a size of 1.2mb, as a result I got a bunch of files, one of which(swflite.bin) is almost 17mb. More than 10 times size increase. Failed to build project, got an error that I can’t embed files with size more than 16mb.
Then I decided to try Loader approach, but I am not sure what I have to load from this bundle directory, so I tried to load this swflite.bin via Loader and failed again. Perhaps I am doing something wrong, it would be great to have some kind of manual of how to do such things correctly. But for now it seems it is not an option to have some assets in .swf files if you want to target html5.
The whole “.bundle” directory is a parallel for the SWF – you can use the “path/to/your.bundle” in
Loader and it will automatically pull the individual files from the directory it needs.
Keep in mind that SWF is a compressed format, but HTML5 works best when you allow the server and the browser to handle compression on their own. The actual comparable size of your bundle is if you zip it yourself and see how large it really is.
I finally decided to export graphic assets from .swfs into .pngs, and to embed using
<library> tag light weight .swfs which mainly contain different empty containers to place stuff. It worked perfectly for me. Anyway thanks for taking time to explain me all this, really appreciate it.
PS. Any plans on supporting GlowFilter in HTML5?
I believe we do support
GlowFilter (but imperfectly) – what kind of filter are you trying to use? Outer? Inner? Knockout?
Tried every kind, nothing works in html5, but works in flash. OpenFL 8.9.0
Try this params
new GlowFilter(0xFF0000, 1, 4, 4, 6)
Does it works for you? Looks like “strength” must be greater than blurs and “quality” must be default
Thanks! This worked for outer glow, inner = true does not make any difference though.
Yes, inner and knockout is not implemented yet
I use this code, and get an error.
openfl.min.js:2 [lime.utils.AssetLibrary] WARNING: Could not find library type: openfl._internal.swf.SWFLiteLibrary
Could you try running
openfl process over the SWF again?
Yes, I try
openfljs process game.swf.
It’s available now.
Doesn’t work for flash target:
[trace] [lime.utils.AssetLibrary] WARNING: Could not find library type: openfl._internal.formats.swf.SWFLiteLibrary
[trace] Test.hx:97: library_onError Could not load asset manifest
The Flash target currently supports standard SWF only, use the unprocessed SWF file on Flash and the processed SWF bundle on others