2013-06-26 69 views

回答

2
//create a reference to the file in the applicationStorage Directory 
//(for more directories, look at http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/File.html 
var fileToCreate:File = File.applicationStorageDirectory; 
fileToCreate   = fileToCreate.resolvePath("myfile.txt"); 

//create a filestream to write to the file 
//the write and/or creating the file is done with the FileMode in the open() function 
//look at the table that describes what FileMode does what here: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/FileMode.html 
var fileStream:FileStream = new FileStream(); 
fileStream.open(fileToCreate, FileMode.WRITE); 

//write some string to the file 
fileStream.writeUTF('this is a string to write to the file'); 

//finally, close the filestream 
fileStream.close(); 

編輯:改變文件模式從讀寫。 READ不會創建課程文件:)

+0

沒有創建,抱歉。 >我將'applicationStorageDirectory'更改爲'applicationDirectory'。 >創建新的空氣應用程序,保存它,Ctrl-輸入它(用於測試),並出現錯誤: > SecurityError:fileWriteResource \t at flash.filesystem :: FileStream/open() \t at CreateTXTfile_AIR_fla :: MainTimeline/frame1 ()[CreateTXTfile_AIR_fla.MainTimeline ::幀1:18] \t在運行時:: ContentPlayer/loadInitialContent() \t在運行時:: ContentPlayer/playRawContent() \t在運行時:: ContentPlayer/playContent() \t在運行時: :AppRunner/run() \t at ADLAppEntry/run() \t at global/runtime :: ADLEntry() –

+0

You無法以無管理員權限寫入applicationDirectory。將其更改回applicationStorageDirectory以查看腳本是否可用 – Marijn

+0

好吧,我將其更改回applicationStorageDirectory。沒有錯誤,但仍然不起作用。沒有創建文件。 :( –

相關問題