0
嗨,我想通過FILESTREAM追加XML節點,但不知道如何在Flash中使用FILESTREAM繼承人的代碼,使其理解 XML文件是AS3的FileStream追加XML節點
<?xml version="1.0" encoding="UTF-8" ?>
<Sounds>
<Value bez="falconp" id="0">
<fad>falconpunch.swf.mp3</fad>
</Value>
</Sounds>
現在我何時啓動IM選擇一個mp3我想添加一個新值節點與時尚和性能的id和BEZ(BEZ意味着文件名只有幾個字符長度)繼承人代碼即時通訊使用
:
public class SoundboardMain
{
public var gui:Soundboard;
// public var req:URLRequest=new URLRequest(string1);
public var sound:Sound;
public var xml:XML=new XML();
public var loader:URLLoader=new URLLoader();
public var file:File=new File();
public var daten:FileStream=new FileStream();
public var expl:File;
public var fileStream:FileStream = new FileStream();
public var bar:ProgressBar=new ProgressBar();
public function SoundboardMain(gui:Soundboard)
{
this.gui=gui;
file = File.documentsDirectory.resolvePath("Sounds.xml");
loader.addEventListener(Event.COMPLETE, komp);
fileStream.open(file, FileMode.WRITE);
// xml = XML(fileStream.readUTFBytes(fileStream.bytesAvailable));
loader.load(new URLRequest("Sounds.xml"));
// fileStream.writeUTFBytes("HELLO");
// fileStream.close();
trace(xml);
loader.addEventListener(Event.COMPLETE, komp);
loader.addEventListener(IOErrorEvent.IO_ERROR ,Error);
}
public function Error(event:IOErrorEvent):void{
trace("Fehler:! "+event.text);
}
public function komp(event:Event):void{
trace("1");
xml=XML(loader.data);
gui.buttonshin();
}
public function custom(event:MouseEvent):void
{
expl=new File();
expl.addEventListener(Event.SELECT, onSelec);
var swfTypeFilter:FileFilter = new FileFilter("Mp3 Dateien","*.mp3;");
expl.browse([swfTypeFilter]);
}
public function onSelec(event:Event):void{
expl.addEventListener(Event.COMPLETE, onCompl);
expl.addEventListener(ProgressEvent.PROGRESS, prog);
expl.addEventListener(IOErrorEvent.IO_ERROR, onFileLoadError);
expl.load()
trace(expl.name);
fileStream.writeUTFBytes(loader.data);
bar.visible=true;
bar.mode=ProgressBarMode.MANUAL;
bar.minimum=0;
bar.maximum=100;
gui.start.addChild(bar);
}
public function prog(event:ProgressEvent):void{
var percentLoaded:Number=event.bytesLoaded/event.bytesTotal*100;
bar.setProgress(percentLoaded, 100);
}
public function onFileLoadError(event:IOErrorEvent):void{
bar.visible=false;
expl.removeEventListener(Event.COMPLETE, onCompl);
expl.removeEventListener(IOErrorEvent.IO_ERROR, onFileLoadError);
expl.removeEventListener(ProgressEvent.PROGRESS, prog);
trace("File load error");
}
// private function saveFile():void
// {
// var writeStream:FileStream = new FileStream();
// /*
// * FileMode.WRITE will truncate (empty) the file on open.
// * FileMode.APPEND will open the file "as is" and write in the end of it.
// */
// writeStream.open(expl, FileMode.WRITE);
// writeStream.writeBytes(data); // Any other write method can be used
// writeStream.close();
// }
public function onCompl(event:Event):void
{
var ur:URLRequest=new URLRequest(expl.name);
// trace(event.target.nativePath);
var string1n:String=new String(event.target.name.substr(0,event.target.nativePath.length-4));
// trace(string1n);
// daten.writeUTFBytes("Hekki");
// var newxml:XML=xml.appendChild("TEST");
// f.save(newxml,"Sounds.xml");
// var fs : FileStream = new FileStream();
// var targetFile : File = File(
// fs.open(targetFile, FileMode.WRITE);
// fs.writeUTF("test");
// fs.close();
//// var ba:ByteArray=new ByteArray();
// trace(xml);
//
}
public function mp3load(event:Event):void{
}
public function image1(event:MouseEvent):void{
var reqe:URLRequest=new URLRequest("https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=philipp%2elippold%40yahoo%2ede&lc=DE&item_name=Solidtron&no_note=0¤cy_code=EUR&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHostedGuest");
// navigateToURL(reqe);
}
}
}
例如,如果我添加和MP3稱爲funk.mp3 BEZ =臨陣脫逃的XML應該像
<?xml version="1.0" encoding="UTF-8" ?>
<Sounds>
<Value bez="falconp" id="0">
<fad>falconpunch.swf.mp3</fad>
</Value>
<Value bez="funk" id="1">
<fad>funk.mp3</fad>
</Value>
</Sounds>
但是這是一個臨時的解決方案,因爲我想這樣可節省它在xml中的程序從xml加載數據並創建按鈕 – Mralladin
不完全確定你的意思。我已經更新了我的示例,包括將XML寫回文件。 – Aaron
它確定它已經但是,有沒有什麼辦法來刪除最後一個節點deappend或什麼,因爲我也想創建一個刪除按鈕^^ – Mralladin