所以目前我能够根据用户的需要保存 1-9 个 AS3 变量,它们作为文本字符串保存到 XML 文件中,但是当用户再次保存时,旧的 xml 信息仍保留在文件中并添加了新信息。但是,我希望新信息要么覆盖旧信息,要么设置一个函数以在保存新设置之前清除/删除 xml 文件中的信息。
这是我当前的保存功能:
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
}
提前致谢。