Flash platform file access

Hallo ALL,

I need to write string into file and read it from file. So I’ve found sys.io package in haxe, but it said to me that I can’t use it, while targeting flash :smile:
Then I tried searching for flash.net.FileReference class in haxe documentation, and I found one! But on compile i’m said that there is no package flash. :flushed:
So the question is: is there any method to store and read text files in flash target (shared object does not fit). And possibly is there any crossplatform method, may be in openfl itself?

The flash player does not have access to the filesystem,
the user can select some folders to be authorized but it’s not really user friendly.
Why does shared object do not fit your need, what are you exactly trying to do?

The sys package is only available for c++,neko and php targets.

Try using the name openfl.net.FileReference.

the reason is to save level from the editor to load it somewhere else or send to friend. I’m making game with editor feature. And I saw other flash games saving files to harddrive (with file dialog).

openfl.net.FileReference also not found. Am I missing something?

You should be able to use flash.net.FileReference conditionally on the Flash platform, only. That’s correct, Flash now supports file saving or loading, through a dialog. You can’t programmatically load or save files without the user interaction

why may compiler say that there is no flash package?

Depends on your target, there should definitely be one #if flash, but it will error otherwise

1 Like

got it! i should also import with conditionals.
it is strange that even if i compile only to flash target, i should use conditional everywhere for compiler to compile the source :smile:

thank you, singmajesty!

If you only compile to the Flash target, then conditional compilation shouldn’t make a difference.