Quick update, we now have hot-reload support for SWF assets in the NPM releases, check out âfeatures/display/UsingSWFAssetsâ or âdemos/NyanCatâ under https://github.com/openfl/openfl-samples-ts to get an example.
In short, you can import a SWF file, and processing is automatically done as a part of the build. The import returns the file path you can use to load it
import * as libraryPath from "./../assets/library.swf";
...
AssetLibrary.loadFromFile (libraryPath);
For anyone using Adobe Animate for Adobe Flash Professional, this provides a hot reload workflow for working with changed SWF assets, and simplifies the process of converting SWFs for use with HTML5
There should be an openfljs command exposed by the OpenFL NPM library, so you can do openfljs process path/to/swf path/to/output.bundle in an NPM script.
The latest release added Haxe generated code output to the bundles, though the classpath wonât be added automatically in NPM releases. I think thereâs more that could be done to improve this
Hi, I find that the *.bundle is folder.
Is there has any way to use âAssetLibrary.loadFromBytesâ to load swf from ByteArray?
Because I might uncompress and read the resource from the â.zipâ file.
Looking forward to your reply, thank you~
You should be able to currently use AssetLibrary.loadFromFile with the path to the *.bundle directory. It will figure out the additional paths from there
We do not have a feature yet to bundle the SWF assets into a flat file (which in testing was not as fast and requires more memory), but a single file does make managing some other things easier, so Iâve had it requested a few times
Are you sure that you are using the latest version of OpenFL with the project?
The âpackage.jsonâ asks for OpenFL version ^7.0.0, so it might not be grabbing the latest version. Could you try running npm install openfl --save-dev and seeing if it updates to a newer version?
EDIT:
I had to actually edit the âpackage.jsonâ and set it to 8.8.0, then run npm install openfl again.
Thereâs probably an easier way to flag a project to use the latest major version
Should it be as follows? git clone https://github.com/openfl/openfl-js
Looking forward to release version.
Hope to add support AssetLibrary.loadFromBytes.
Hope to ByteArray supports [] accessor.(Now it can be simulated by Proxyďźbut native support is best.) let ba = new ByteArray(); ba.writeByte(0x00); console.log(ba[0]);
Oops! I forgot the one step. When in the OpenFL directory, run:
npm build -s
This should rebuild the OpenFL library and tools.
What happens if you run AssetLibrary.loadFromBytes? Is it supported? Does it have an error?
JavaScript (unfortunately) supports the array accessor only on the Array object (not even something that has Array in its prototype chain!) or if you add a real property. We hacked in support for openfl.Vector, but ByteArray currently uses get or set methods as a workaround
We did not expose ByteArray.fromArrayBuffer to the NPM release, but perhaps we could. Would that help? I know its not the same as Buffer, but might fill a similar use-case
Yes, I run it in openfl path, or you means project folder?
I canât run AssetLibrary.loadFromBytes, because *.bundle is folder.
I think itâs not necessary support [] on Array object, for example:
let ba = new Proxy(new ByteArray(), {
get: (ba: ByteArray, key) =>
{
let i = key as number;
if (i >= 0 && i <= ba.length)
{
let position = ba.position;
ba.position = parseInt(i as any);
let result = ba.readByte();
ba.position = position;
return result;
}
return ba[i];
},
set: (ba: ByteArray, key, value) =>
{
let i = key as number;
if (i >= 0 && i <= ba.length)
{
let position = ba.position;
ba.position = parseInt(i as any);
ba.writeByte(value);
ba.position = position;
}
else
{
ba[i] = value;
}
return true;
}
});
ba[0] = 0x11;
console.log('ba.position:', ba.position);
console.log('ba.length', ba.length);
console.log('ba.readByte()', '0x' + ba.readByte().toString(16));
After opening VPN, the command run successfully.
Our countryâs GFW is really strong, haaaaâŚ
I strongly hope that supporting bundle the SWF assets into a flat file.
Because I found that so many resource files were created.
Besides, do you have other recommended UI editors for openfl except Adobe Animate and Adobe Flash Professional?
Thanks a lot for your previous answers.
As follows, it seems that the some instances lost after publishing.
import * as ui_path from "./../assets/ui.swf";
AssetLibrary.loadFromFile(ui_path).onComplete((library: AssetLibrary) =>
{
let bi = this.addChild(library.getMovieClip('StartButton'));
bi.x = 200; bi.y = 100;
}
Thatâs a correction, no missing instances.
The bitmap pixels seem to be set transparent in child movieclip.