Embed="true" in <library> prevents me from using my .swf's movieclips, “AL lib: (EE) alc_cleanup: 1 device not closed” error


#1

Hi, I have a simple question, I need to access assets(movieclips) from an external .swf file & I use the embed=“true” in the tag to prevent my assets from being exposed on compile, the problem is when i do that I can’t use/access the .swf file’s contents using the methods explained in “Using swf assets” tuto, when I try to run it gives me the “AL lib: (EE) alc_cleanup: 1 device not closed” error with the window closing right after it appears when I run the project.
If I set it to false or omit it, everything works fine but the assets are exposed that way. So how do I access the movieclip assets from the .swf while embed=“true” ?
I’ve seen that there are @:bitmap, @:font, @:sound or @:file for using those kinds of embedded resources but there’s none for movieclips?
In case I can’t rely on the embed=“true” method, is there any other simple way to prevent my assets from being exposed at compilation/release? I’ve done a thorough searching in the forums & sites practically whole day yesterday without finding a solution to this other than trying to convert the assets into bytecode but I need a simpler/ready solution.
I’ve seen this issue being discussed since at least 2015 or even 2014 and now 3/4 years later there still isn’t a solution to that problem?
How do people actually publish their games using Openfl in this case if there’s no simple standard solution to protect their assets?


#2

The short answer? They don’t protect their assets. Whether you use Flash, OpenFL, Unity, or really anything else, your code and your art will be accessible to anyone motivated enough.

You can take steps to deter novices, but that’s about it.


#3

Yeah ik and thanks for the reply, deterring novices was about my intention, can you please hint me to that? Even if it requires coding like using ByteArrays as long as there’s a tuto or sample code of how to do it.


#4

To deter novices, you could encrypt the data beforehand and decrypt it at runtime. To make sure nothing is lost in translation, you probably want to use Haxe for both steps. That means you need a second OpenFL app that will process your assets before you compile your main app.

Use one of the symmetric encryption options. Don’t worry about choosing one that’s cryptographically secure; just pick the fastest. Its only job is to mix up the data enough that programs won’t automatically recognize the format.

There are some even simpler options you could try, but in those cases, programs might see right through it:

  • You could try deleting the file extensions and manually telling OpenFL how to interpret them. Problem is, modern browsers can see right through that sort of thing. If you make a PNG and change the extension to .jpg, your browser will display it anyway. It’ll even tell you that the image is really a PNG.
  • You could forget about cryptography and instead just compress your ByteArray. But if you save a file like that, it’s entirely possible that programs like 7-Zip will easily open it. (I’m actually not sure, but I wouldn’t be surprised.)

Anyway, back to encryption. Once you’ve encrypted, embedded, and decrypted the SWF, all you need to do is call new format.SWF(decryptedByteArray) and you’re good to go.

Two final notes:

  1. haxe-crypto and OpenFL each provide their own implementation of ByteArray. You’ll need to use toBytes() and fromBytes() to bridge the gap.
  2. Parsing the SWF at runtime means you’ll be missing out on some of OpenFL’s compile-time optimizations.

#5

Ok thanks for your reply, I’m not familiar with any of this so I’m not really sure if I’d be able to do it properly but I’ll try & do the research, in the meantime if there’s any tuto you know of that could help or speed things up please lemme know.


#6

The assets “pak” feature may also help. It could be modified to encrypt as well as packing assets


#7

I’m actually fine with just packing, in fact that’s the kind of thing I was looking for but I dunno why when I tried it before it didn’t generate the .pak for me but now that I tried again it just worked o_o might be cuz I didn’t try a Clean Build at that time before I added the -clean, just one thing please how do I access the content i.e movieclips from the .pak ? The setup is as follow:
I have 1 ForestCharacters.swf file in my assets folder, in my project.xml I have:
< library name=“ForestCharacters” type=“pak” />
< assets path=“assets/ForestCharacters.swf” library=“ForestCharacters” />
Then in the code:
Assets.loadLibrary (“ForestCharacters”).onComplete (function (library)
{
addChild(Assets.getMovieClip(“ForestCharacters:TurtleGolemSouthClip”) );
});
When I run the app, it shuts immediately with AL lib: (EE) alc_cleanup: 1 device not closed error.


#8

Ah, it might not be compatible with SWF yet. Maybe that was the issue


#9

Alright, but what about the embedding? isn’t there a way to access movieclips if we use embed=“true” in the library node like it’s possible for fonts, bitmaps or sounds via their resp. @tags?


#10

My objective is simply to make the frame png images in the bin/lib folder that were generated from the .swf file to be not directly visible in that form, kinda like what the pak feature does, I don’t really seek heavy encryption just something basic, same for sound files etc, is there any post or tool that does or explain how to do that please? This isn’t an issue when targeting the web platform but for desktop it’s quite a basic need.


#11

You can’t mix type “pak” with type “swflite” right now, but how we generate or how we parse the SWF output is certainly doable, but nothing I can clearly point to that would not require some work to do. I wonder if we could design a way to combine the two


#12

Ok thank you for the reply :slight_smile:


#13

Interesting solution. I’m quite new to Haxe so this is a nice challenge to start with.
In a adventure game I’m making for Android/iOS (Air) I am planning to add all my frame-by-frame and motion-tweened animated bitmap assets an swf for every scene file and from now on this will be encrypted.

For those who are interested: https://github.com/hampelman/encryptSWF

It works in rather a roundabout way by converting Bytes in 16 byte long ByteArray blocks and if you want to use it the way Player_3 describes, new format.SWF(decryptedByteArray), you even need a second type of ByteArray, namely flash.utils.ByteArray.

Do I really need to use the swf lib to display the swf or is there an OpenFL solution?


#14

Another question: if I try to display the decrypted SWF with
var swf = new format.SWF(swfArray);
addChild(swf.createMovieClip());

I get the error message:

param 1 incompatible
virt Object flash.display::MovieClip/gotoAndPlay()
over * format.swf.instance::MovieClip/gotoAndPlay()

param 1 incompatible
virt Object flash.display::MovieClip/gotoAndStop()
over * format.swf.instance::MovieClip/gotoAndStop()

VerifyError: Error #1053

While the width, the height and the instances properties are readable and make sence.
Does anyone have a clue?


#15

The SWF library has been merged into OpenFL, it now lives internally at “scripts/format/swf” within the OpenFL directory. Internally, OpenFL uses the “swflite” format for MovieClip animation, while Adobe Flash Player still uses the standard SWF format.

Our command-line tools process SWFs to either link the original SWF as a lib for Flash Player, or to process the SWF using the SWFLiteExporter class, which takes the parsed SWFTimelineContainer representation, and converts it into the format.SWFLite data format, which OpenFL understands at runtime.

We don’t use the format.SWF class right now, and it may likely be a little broken. It was too slow for native (compared to SWFLite) and didn’t work well for HTML5, if at all.

We might consider bringing this support back for runtime SWF parsing, but right now you can `openfl process Test.swf" to generate a “Test.bundle” directory which OpenFL should be able to open at runtime.

This is basically going back to the Lime AssetLibrary system, where we process a SWF, and generate an asset library for it, to be included at compile-time, or loaded later at runtime. The PackedAssetLibrary class is a custom asset library type, but perhaps we could make a PackedSWFLiteAssetLibrary or something of the sort, or visit ideas to improve the system (like chaining between asset processors to add encryption or other logic in there)


#16

Thanks for your eleborate answer Joshua; it gives me more insight in OpenFL.
I think I’m going for the pak-ed and encrypted swflite solution for my game. And see if my programming skills reach as far as extending the command-line tool.

However, my encrypt-swf-eperiment is not complete without having the encrypted swf actually on screen. Does anyone know if Haxe’s native flash packet has a way of displaying a swf loaded to memory as a ByteArray?