actionscript 3 - Writing in txt file on AS3 - 1120: Access of undefined property FileMode -
i trying write in .txt
file using as3, unfortunately can't compile code. followed several tutorials , couldn't fix problem. if it's possible me.
import flash.events.mouseevent; import flash.net.urlloader; import flash.filesystem.file; import flash.net.urlrequest; import flash.filesystem.filestream; stop(); mybutton.addeventlistener(mouseevent.click, loadcomplete); function loadcomplete(event:mouseevent):void { var file:file = file("test.txt") var stream:filestream = new filestream(); //stream.open(file, filemode.write); stream.open(file,filemode.write); stream.writeutfbytes("this text file."); stream.close(); }
the error receiving "1120: access of undefined property filemode.
". sorry bad english.
the error shown because doesn't import filemode
class.
import flash.filesystem.filemode;
note : adobe air version supports `file, in knowledge.
- if want write
test.txt
file without prompt
var file:file = file.desktopdirectory.resolvepath("test.txt"); var stream:filestream = new filestream(); stream.open(file,filemode.write); stream.writeutfbytes("this text file."); stream.close();
- if want write prompt
import flash.filesystem.*; import flash.events.event; var docsdir:file = file.documentsdirectory; function loadcomplete(event:mouseevent):void { try { docsdir.browseforsave("save as"); docsdir.addeventlistener(event.select, savedata); } catch (error:error) { trace("failed:", error.message); } } function savedata(event:event):void { var newfile:file = event.target file; var str:string = "hello."; if (! newfile.exists) { var stream:filestream = new filestream(); stream.open(newfile, filemode.write); stream.writeutfbytes(str); stream.close(); } }
Comments
Post a Comment