开发者

ActionScript 3: How to save binary data to files

im doing a level editor for my game and i need to save the tilemap data (120x120 uint array) and character data (character 开发者_Go百科type, position, rotation, stats, etc) to a .bin file. How can i do it? I know i can do it by using XMLs but it is not good for saving tilemaps... Thanks


What you are looking for is the FileReference class's save function. See here: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html#save()

This only works in Flash Player 10+, and requires user interaction. (It'll pop up a save dialog box) These restrictions are there for security reasons, if you want to be able to save flies directly (without user interaction), you'll have to use AIR, see the FileStream class ref for that: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/FileStream.html

To save native Flash objects to an external file and load them in again, you'll need to write the data to a ByteArray first. ByteArray has two methods (writeObject & readObject) that make this trivial. see here: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/ByteArray.html

Good luck.


If it is a web based game, to be run in a web browser, and you want to save the data on the users system (not on a web server), I can think of two options:

If it is OK to require Flash Player 10, you can save and load data to and from local files on the users request, such as a button click, (not arbitrary from anywhere in your code) and via a standard file dialog. See FileReference.save().

You can also store data in a local SharedObject. The data can be read and written without user interaction or a file dialog. Flash Player then serializes the data for you, but I think you should be able to save the kind of data you describe that way.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜