I tried to check the hit code on an Android device, but I could not see any data in the text fields. This code works well on AIR Desktop , but not on Android . Difference between AIR FileStream function on Desktop and Android ? What is the best cross-platform code for saving files and reading records?
This code runs on the Adobe Animate CC Android Emulator .
import flash.filesystem.*; var prefsFile:File; [Bindable] var prefsXML:XML; var stream:FileStream; function appStart():void { prefsFile = File.applicationStorageDirectory; prefsFile = prefsFile.resolvePath("preferences.xml"); readXML(); } function readXML():void { stream = new FileStream(); if (prefsFile.exists) { stream.open(prefsFile, FileMode.READ); processXMLData(); } else { saveData(); } } function processXMLData():void { prefsXML = XML(stream.readUTFBytes(stream.bytesAvailable)); stream.close(); trace(prefsXML.Data1); trace(prefsXML.Data2); trace(prefsXML.Data3); txt_D1.text = prefsXML.Data1; txt_D2.text = prefsXML.Data2; txt_D3.text = prefsXML.Data3; } function windowClosingHandler(event:Event):void { saveData(); } function saveData():void { createXMLData(); writeXMLData(); } function createXMLData():void { prefsXML = <preferences/>; prefsXML.Data1 = 1; prefsXML.Data2 = 2; prefsXML.Data3 = 3; } function writeXMLData():void { var outputString:String = '<?xml version="1.0" encoding="utf-8"?>\n'; outputString += prefsXML.toXMLString(); outputString = outputString.replace(/\n/g, File.lineEnding); stream = new FileStream(); stream.open(prefsFile, FileMode.WRITE); stream.writeUTFBytes(outputString); stream.close(); } appStart();
source share