A
A
Alexander Sharomet2014-03-05 22:45:57
Android
Alexander Sharomet, 2014-03-05 22:45:57

Actionscript3.0 for android - how to save data in the game?

Hello.
I have a question. There is, for example, a game, and you have passed the first level, you need to save this information so that the user does not pass it again, how to do this?
Please post some code or links.
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Flasher, 2014-03-14
@sharomet

Once I wrote a class for working with files in Air-e

package ua.alexvoz.arena.utils {
  import flash.display.Sprite;
  import flash.filesystem.File;
  import flash.filesystem.FileMode;
  import flash.filesystem.FileStream;
  
  /**
   * @author ALeXVoz 
   * http://alexvoz.net/
   * E-mail: [email protected]
   * ICQ: 232-8-393-12
   * Skype: alexvozn
   */
  public class FileUtils extends Sprite {
    
    public function FileUtils() {
      super();
    }
    
    public static function createDocumentDerictory(dirName:String):void {
      var _dir:File = File.applicationStorageDirectory.resolvePath(dirName);
      if (!_dir.exists) _dir.createDirectory();
    }
    
    public static function saveUTFTextFile(flName:String, flData:String):void {
      var _fl:File = File.applicationStorageDirectory.resolvePath(flName);
      var _flStream:FileStream = new FileStream();
      _flStream.open(_fl, FileMode.WRITE);
      _flStream.writeUTFBytes(flData);
      _flStream.close();
    }
    
    public static function openUTFTextFile(flName:String):String {
      var _fl:File = File.applicationStorageDirectory.resolvePath(flName);
      var _flStream:FileStream = new FileStream();
      _flStream.open(_fl, FileMode.READ);
      _flStream.position = 0;
      var _data:String = _flStream.readUTFBytes(_flStream.bytesAvailable);
      _flStream.close();
      return _data;
    }
    
    public static function checkFileCreated(flName:String):Boolean {
      var _dir:File = File.applicationStorageDirectory;
      if (_dir.resolvePath(flName).exists) return true
      else return false;
    }
    
    public static function checkDirCreated(dirName:String):Boolean {
      var _dir:File = File.applicationStorageDirectory.resolvePath(dirName);
      if (_dir.exists) return true
        else return false;
    }
  }
}

I wrote for a long time. Not sure about performance. But it is clear in which direction you need to dig, the list of classes and commands can be underlined.
These methods also work in mobile Air. The main thing is to understand the correct handling of the file system File.applicationStorageDirectory.resolvePath(flName)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question