Skip to content

Instantly share code, notes, and snippets.

@litvil
Last active August 29, 2015 14:23
Show Gist options
  • Save litvil/b1dd03c74036cab685ca to your computer and use it in GitHub Desktop.
Save litvil/b1dd03c74036cab685ca to your computer and use it in GitHub Desktop.
Code changes AIR application id, and it is posible to launch many same applications
public static function changeAirAppId():void {
var file:File = File.applicationDirectory.resolvePath(APP_CONF_PATH + APP_CONF_FILE);
Logger.log(file.url);
if (file.exists) {
var ObiectXML:XML = readXMLFromFile(file);
var ns:Namespace = ObiectXML.namespace();
var time:Date = new Date();
ObiectXML.ns::id[0] = 'Bot' + time.valueOf().toString();
var sourceFile:File = File.applicationStorageDirectory.resolvePath(APP_CONF_FILE);
var destination:File = new File(file.nativePath);
writeXMLToFile(ObiectXML, sourceFile);
sourceFile.moveTo(destination, true);
}
}
private static function writeXMLToFile(xml:XML, file:File):void {
var fs:FileStream = new FileStream();
fs.open(file, FileMode.WRITE);
fs.writeUTFBytes(xml.toXMLString());
fs.close();
fs = null;
}
private static function readXMLFromFile(appXMLFile:File):XML {
var xml:XML;
var fs:FileStream = new FileStream();
fs.open(appXMLFile, FileMode.READ);
var contents:String = fs.readUTFBytes(fs.bytesAvailable);
fs.close();
fs = null;
xml = new XML(contents);
return xml;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment