mardi 31 janvier 2017

Adobe AIR Android XML Write Read issue

I tried to test blow code on android device but i couldn't see any data to text fields. This code works well on AIR Desktop but in android no. Is it difference between AIR FileStream function on Desktop and Android? Whats best cross platform code to save files and read write?

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();

Aucun commentaire:

Enregistrer un commentaire