Port to Html5 target

I´m using this code in my project but dont work in html5:

import sys.io.File;

and this:

var fileW = File.write("img/Graphics.json");

how is the best way to do that? in html5

What are you trying to accomplish by writing to Graphics.json?

Are you saving something for the user’s benefit? If so, I believe there’s a way to show a “save file” dialog.

Are you saving data that the app will use later? If so, consider using a SharedObject. (You can have multiple at once, don’t worry.)

1 Like

i need to save json files and read later again, just that, in android target i have the same problem, it crash whem i try to save or read the json file

Different platforms can be picky about where you can and can’t put data. For instance, Android makes a special directory for your app, and if you want to put a file anywhere else, you need to ask permission first.

OpenFL’s SharedObject class handles all of this for you. It looks up where the folder is, makes a new file there, and lets you read from/write to it. Also: a JSON file is really just a long string, and SharedObjects are perfectly capable of storing long strings.

I use in one game SharedObject for save game, but that we cant share like a json file, a need to write in json file so if you save something you can share with others players your creation, can SharedObject be share like an xml or json?

So the idea is that you create a JSON file, they post it on some file-sharing service, and then other users can download it?

The best way to handle this is to use a backend. The app uploads the JSON string, and then the server makes it available to everyone else. You can do this with PlayerIO, which will enable you to add extra features later, such as filtering and sorting. You could do this by submitting to Pastebin, which might be easier to set up but won’t scale very well.

If you don’t want to bother with any of that, then the next-best option is to make the user copy a string. File management is hard on mobile devices, but copy-pasting is easy.

1 Like