actionscript 3 - How to write files to a specific directory? -
i'm trying let user select directory , write files directory.
i have code lets user browse directory:
var file:flash.filesystem.file = new flash.filesystem.file(); file.browsefordirectory("select directory"); file.addeventlistener(event.select, selecthandler); protected function selecthandler(event:event):void { // these contain path want save files object(filereference).url; object(filereference).nativepath; // how create file in directory? }
how create file in directory user selects?
your select handler code not seem correct. should reference of folder object of type file
doing event.currenttarget
, , not object or filereference.
next can create file using filestream
class. selecthandler
code should this:
protected function selecthandler(event:event):void { var targetdirectory:file = event.currenttarget file; var file:file = targetdirectory.resolvepath("htmlfile.html"); var stream:filestream = new filestream(); stream.open(file, filemode.write); stream.writeutfbytes("any text want create"); stream.close(); }
will work in air projects.
hope answers question.
Comments
Post a Comment