2007-06-20

AIR 存檔測試

Flash Frame Actions:
import flash.filesystem.*;
// var file:File = File.documentsDirectory; // 我的文件
var file:File = File.applicationResourceDirectory; // 應用程式所在的目錄
file = file.resolve("test.txt");
trace(file.nativePath); // 於 DOS 視窗輸出

function doSave(e:MouseEvent):void {
var fileStream:FileStream = new FileStream();
fileStream.open(file, FileMode.UPDATE);
// File.systemCharset 為系統編碼
//fileStream.writeMultiByte(_txt.text, File.systemCharset);
fileStream.writeMultiByte(_txt.text, "utf-8");
fileStream.close();
}
function doLoad(e:MouseEvent):void {
var fileStream:FileStream = new FileStream();
try{
fileStream.open(file, FileMode.READ);
//_txt.text = fileStream.readMultiByte(file.size, File.systemCharset);
_txt.text = fileStream.readMultiByte(file.size, "utf-8");
}catch(err:IOError){
_txt.text = "No data!";
}
fileStream.close();
sbar.update();
}
function doClear(e:MouseEvent):void {
_txt.text = "";
sbar.update();
}
save_btn.addEventListener(MouseEvent.CLICK, doSave);
load_btn.addEventListener(MouseEvent.CLICK, doLoad);
clear_btn.addEventListener(MouseEvent.CLICK, doClear);

原始檔: saveTextFile.fla

1 則留言:

Unknown 提到...

您好
想請問這範例我試過FLA直接發布後,並不會執行任何動作,是需要哪些設定呢?

感謝您 ^^

FB 留言