因此,目前我能夠保存1到9個AS3變量,具體取決於用戶想要的內容,它們作爲文本字符串保存到XML文件中,但是當用戶再次保存時,舊的xml信息保留在文件並添加新信息。 但是,我希望新信息可以覆蓋舊信息,或設置一個函數來清除/刪除xml文件中的信息,然後再保存新的設置。使用AS3刪除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 />
[email protected] = 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
}
在先進的感謝。
我不知道爲什麼你的問題是downvoted,因爲負責人並未對此置評。我不認爲downvote是合適的,所以我upvoted。 –
謝謝你,我也有點困惑。 – user1414344