Saving and Loading files from an Android mobile Device using Flash Actionscript 3.0 -
Saving and Loading files from an Android mobile Device using Flash Actionscript 3.0 -
im making test maker app both desktop , android. able save , load in desktop failed on android. can save file, cannot load saved file. android device says "no files found". doesnt open file browser. type of saving , loading im doing type user can project , open it. im using filereference this. works on desktop not on android mobile. can help me this?
i'm pretty sure can't utilize filereference
on mobile (though sense free right me if wrong).
on mobile, should utilize file
& filestream
classes loading/saving local files.
here example, of using compile time constant create (to determine if desktop or air) , loading appropriately , out of textfield called textfield
:
config::air { var file:file = file.applicationstoragedirectory.resolvepath("myfile.txt"); if(file.exists){ var stream:filestream = new filestream(); stream.open(file, filemode.read); textfield.text = stream.readutf(); //this may need changed depending kind of file info you're reading stream.close(); }else{ info = "default value"; //file doesn't exist yet } } config::desktop { //use file reference code populate info variable }
and save: (assuming have textfield text want save)
var filestream:filestream = new filestream(); filestream.open(file, filemode.write); filestream.writeutf(textfield.text); filestream.close();
there other save methods besides writeutf
(which plain text) writeobject
saving custom object when combined flash.net.registerclassalias
file classes in flash.filesystem
package
edit
here can seek letting user pick location on air.
var file:file = file.applicationstoragedirectory; file.addeventlistener(event.select, onfileselected); file.browseforopen("open file", [new filefilter("text files", "*.txt")]); function onfileselected(e:event):void { var stream:filestream = new filestream(); stream.open(e.target file, filemode.read); textfield.text = stream.readutf(); }
var savefile:file = file.applicationstoragedirectory.resolvepath("myfile.txt"); savefile.addeventlistener(event.select, onsaveselect); savefile.browseforsave("save file"); function onsaveselect(e:event):void { var file:file = e.target file; var stream:filestream = new filestream(); stream.open(file, filemode.write); stream.writeutf(textfield.text); stream.close(); }
android actionscript-3 flash saving-data
Comments
Post a Comment