前端之家收集整理的这篇文章主要介绍了
as3加载外部xml,并在其子节点上添加子节点,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
package
{
import flash.display.MovieClip;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.Event;
public class XmlTest extends MovieClip
{
public function XmlTest()
{
// constructor code
var myXml:XML=new XML();
var XML_URL:String = "0220试验.xml";
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener("complete",xmlLoaded);
}
public function xmlLoaded(event:Event):void
{
trace("Data loaded.");
var loader:URLLoader=event.target as URLLoader;
var xmlDoc=new XML(loader.data);
if(xmlDoc.toString().indexOf("shortKey")!=-1)
{
trace("存在");
wItem=(<node type="rightMenu" cid="rightMenu01_ZX" cname="右键菜单" x="0" y="0" width="1024" height="728" selected="false" menu="null"/>);
xmlDoc.child(0).appendChild(<node type="rightMenu" cid="rightMenu01_ZX" cname="右键菜单" x="0" y="0" width="1024" height="728" selected="false" menu="null"/>);
trace(xmlDoc.child(0).toString());
}
}
}
}