2012-03-26 56 views
0

我正在尋找一種快速簡單的方法來將變量存儲在文本文件中,而不是使用amfphp連接到數據庫,我需要做的就是每次單擊按鈕時遞增值。Actionscript 3.0 - 遞增文本文件

如果所有的變量都在同一個文本文件中,但如果必須每個變量都有一個,那麼會更好。

+0

你打算在你的服務器或用戶計算機上保存你的文件? – shanethehat 2012-03-26 09:06:12

回答

1

如果你的應用程序是一個桌面的,你可以在用戶AIR的File和FileStream類追加模式,就像這樣:

 // create the file reference 
     var file:File = File.documentsDirectory; 
     file = file.resolvePath("air_tests/saved_by_AIR.txt"); 

     // create a stream object to read/write, and open in in APPEND mode 
     var stream:FileStream = new FileStream(); 
     stream.open(file, FileMode.APPEND); 

     // add a new line to the text file 
     stream.writeUTFBytes((new Date()).toString() + "\n"); 
1

桌面應用程序可以使用AIR的File和FileStream類。

查看protozoo的例子。

但是,如果需要加密,請使用EncryptedLocalStore類。

var myVar:int=100; //This is what you'll increemnt. 
var bytesToWrite:ByteArray=new ByteArray(); 
bytesToWrite.writeInt(myVar); 
EncryptedLocalStore.setItem("myVar", bytesToWrite); 

中檢索值,

var storedValue:ByteArray = EncryptedLocalStore.getItem("myVar"); 
var readVar:int=storedValue.readInt();