Actionscript 3 AdobeAIR-FileStream可以在本地保存,但不会触发任何事件
我正在应用程序存储中本地编写一个utf文件。文件写入正确,但不会触发任何事件Actionscript 3 AdobeAIR-FileStream可以在本地保存,但不会触发任何事件,actionscript-3,air,save,storage,Actionscript 3,Air,Save,Storage,我正在应用程序存储中本地编写一个utf文件。文件写入正确,但不会触发任何事件 public static function saveFileToStorage (path:String, file:*):Boolean { // This savea a ByteArray as a binary or a string as an UTF8 somewhere... var f :File = File.
public static function saveFileToStorage (path:String, file:*):Boolean { // This savea a ByteArray as a binary or a string as an UTF8 somewhere...
var f :File = File.applicationStorageDirectory.resolvePath(path);
// create a file stream
var fs:FileStream = new FileStream();
fs.addEventListener (Event.COMPLETE, onFileSaved);
fs.addEventListener (Event.CLOSE, onFileSaved);
fs.addEventListener (IOErrorEvent.IO_ERROR, onFileSavedError);
fs.addEventListener (OutputProgressEvent.OUTPUT_PROGRESS, onFileSavedOutputProgress);
fs.addEventListener (ProgressEvent.PROGRESS, onFileSavedProgress);
// open the stream for writting
fs.open (f, FileMode.WRITE);
// write the string data down to the file
if (file is String) fs.writeUTFBytes(file);
else fs.writeBytes(file);
return true;
}
public static function onFileSaved (e:Event):void {
Debug.debug (_debugPrefix, "File saved successfully.\n"+e);
}
public static function onFileSavedOutputProgress (e:Event):void {
Debug.debug (_debugPrefix, "File save output progress...\n"+e);
}
public static function onFileSavedProgress (e:Event):void {
Debug.debug (_debugPrefix, "File save progress...\n"+e);
}
public static function onFileSavedError (e:Event):void {
Debug.error (_debugPrefix, "File save error.\n"+e);
}
文件已正确保存,但未触发任何事件。。。没有什么娜达。。。
这正变得神秘。。。
有什么提示吗
谢谢您明确要求FileStream不要触发任何事件,那么您为什么希望触发任何事件呢?出于这个原因,这个问题没有任何意义
FileSteam.open = syncronous and no event fired.
FileStream opanASync = asynchronous and events fired.
使用
open
会导致写入操作同步,因此不会触发任何事件,因为在写入操作完成之前,不会执行以下行。这是一个常见的误解,因为openAsync
在文档中不经常使用。查看Adobe文档在这一点上相当模糊。我不是在打开,而是在磁盘上写。开幕式如期举行。你是说它要么在运行时抛出一个错误,要么一切正常?