Methods to Load / Update Skin Data:

-          There are two methods “loadConfig()” & “updateConfig()”, both methods require File operation.  These methods are using “File” & “FileStream” objects.

o   “File” object creates a pointer to the configuration file & “FileStream” object is used to open configuration file for reading or writing the data.

 

      // load configuration data from XML file

private function loadConfig():void

{

      // resolve the file path of config file

      configFile = File.applicationStorageDirectory.resolvePath("config.xml");

      // incase file doesn't exist copy to storage directory

      if(!configFile.exists)

      {

            configFile = File.applicationDirectory.resolvePath("config.xml");

            configFile.copyTo(File.applicationStorageDirectory.resolvePath("config.xml"));

      }

      // create a file stream object to read config file

      fStrm = new FileStream();

      // read config

      fStrm.open(configFile, FileMode.READ);

      // getting XML content

      configData = XML(fStrm.readUTFBytes(fStrm.bytesAvailable));

      // change skin

      changeSkin(configData.skin);

      // close file

      fStrm.close();

}

           

// save changes back to XML

private function updateConfig(ParamValue:String):void

{

      // load current file to update the value

      var configOld:File = File.applicationStorageDirectory.resolvePath("config.xml");

      fStrm = new FileStream();

      // open it in write mode

      fStrm.open(configOld, FileMode.WRITE);

      // form new data for config file

      var strNewData:String = '<?xml version="1.0" encoding="UTF-8"?>';

      strNewData += configData;

      // wirte new data

      fStrm.writeUTFBytes(strNewData);

      fStrm.close();

}

 

 

-           loadConfig()” will do read operation. First it’ll try to read the configuration file from the Application storage directory. If it doesn’t found the file then it’ll copy the existing file to that directory & then load the data.

o   Using “applicationDirectory” I was getting security error and after some googling I found a LINK for this solution HERE or you can go directly to the solution URL HERE.

 

-          updateConfig()” will update the config file with new data (skin detail).