AssetLibrary.loadFromFile problem


I am trying to load a processed(via “openfl process” command) swf like this:


But getting runtime error:

Uncaught SyntaxError: Unexpected token P in JSON at position 0

What am I doing wrong?

This is related to malformed JSON. Is there somewhere you’re parsing JSON?

It looks like openfl trying to parse JSON from and fails somewhere.

I have exactly the same problem. I create simple swf (only with red square) and when I’ve tried to load it with:
I got same error.

Yes, but I don’t want to embed swf file. I want to load external (because I change files from time to time) that is why I need AssetLibrary.loadFromFile

Now this is where the good old JavaScript creates a problem. The language :smiley: barrier. Even if you embed the swf file with embed tag, it will not get embedded. The engine will load it from the net. So, there is no need to be worried. There is no actual embedding involved because there is actually no method of embedding in html5, rather than string. Once you embed the swf file you can change images inside the zip and redeploy it manually. But, I don’t think you want to do that because its risky. You should set up your build pipeline - system if you want to change swf assets rapidly.

Actually we walked away from main question: there is a problem using .zip file :slight_smile:

at position 0 usually indicates a memory problem. Maybe your file is bigger than buffer can handle or you are not loading it at all.

If it is a SWF loaded with zip, this should help you

1 Like

Thanks for the answer. Unfortunately this doesn’t seem to work with the npm version.

Well, this solution is like option how it works but still I have to add definition in my project.xml.
<library path="assets/graphics/Motivator1.swf" id="swf-library"/>.
Can it even works if I had some XML game settings where I can put optional file path?
OR, let me be explicit: I don’t want any <library path=""> definition,

The solution I provide should be applicable to openfl9 The 1.0 + version does not require any XML configuration.