Using 'File' to save scene object locations to rebuild later in AS3

后端 未结 5 1517
难免孤独
难免孤独 2020-12-02 03:20

I am attempting to use the \'File\' function in ActionScript 3 to save the following information:

I have varying draggable display objects in the scene, the amount a

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-02 03:38

    var bytes:ByteStream;
    var filename:String = "mySaveFile.sav";    
    
    //[...] //initialize byte stream with your data 
    
    //get a reference to where you want to save the file 
    //(in this example, in the application storage directory, 
    //which is fine if you don't need to move the save file between computers
    
    var outFile:File = File.applicationStorageDirectory;
    outFile = outFile.resolvePath(fileName);
    
    //create a file output stream, which writes the byte stream to the file 
    var outStream:FileStream = new FileStream();
    outStream.open(outFile, FileMode.WRITE);
    outStream.writeBytes(bytes, 0, bytes.length);
    outStream.close();
    
    
    //to load the file:
    var inFile:File = File.applicationStorageDirectory;
    inFile = inFile.resolvePath(fileName);
    
    bytes = new ByteArray();
    
    var inStream:FileStream = new FileStream();
    inStream.open(inFile, FileMode.READ);
    inStream.readBytes(bytes);
    inStream.close();
    

提交回复
热议问题