So currently I am able to save 1-9 AS3 variables depending on what the user wants, they are saved as text strings into an XML file however when the user saves again the old xml information remains in the file and the new information is added.
However I want the new information to either write over the old information or set a function to clear/delete the information in the xml file before the new settings are saved.
Here is my current save function:
var soundVAR;
var conditionVAR;
var soundtoXML:XML;
var conditiontoXML:XML;
var test = 1;
var playingCounter = 0;
var xml:XML = <saved>
</saved>;
//1.Button event listener
btn_Save.addEventListener(MouseEvent.CLICK, saveXML);
//2.The saveurl function which opens a URL.
function saveXML(event:MouseEvent):void {
var conditionsArray = new Array(play1Condition, play2Condition, play3Condition, play4Condition, play5Condition, play6Condition, play7Condition, play8Condition, play9Condition)
for (var i=0; i < conditionsArray.length; i++){
trace(conditionsArray[i])
if(conditionsArray[i] == true)
{
soundVAR = soundsName[i];
conditionVAR = conditionsArray[i];
playingCounter++;
} else {
trace('no sounds are playing');
}
while (xml.item.length() < playingCounter ){
var soundString:String = '<sound>' + soundVAR + '</sound>';
var conditionString:String = '<condition>' + conditionVAR + '</condition>';
soundtoXML = new XML(soundString);
conditiontoXML = new XML(conditionString);
var item:XML = <item />
item.@id = xml.item.length().toString();
xml.appendChild(item);
var sound:XML = xml.item[xml.item.length() - 1];
var condition:XML = xml.item[xml.item.length() - 1];
sound.appendChild(soundtoXML);
condition.appendChild(conditiontoXML);
}
}
writeXML();
trace(xml);
}
function writeXML(){
var savedSounds:SharedObject = SharedObject.getLocal( 'savedSounds');
savedSounds.data.soundsxml = xml; // your variables
savedSounds.flush(); // stores data into disk
}
Thanks in advanced.
Short answer: you want to call
xml.item.setChildern('');before thewhileloop. Longer answer: I don’t understand the last 4 lines of the while loop. Can you explain what was the intent behind writing them?If I understood your code correctly, then the while loop could look like so: