当前位置:软件学习 > Flash >>

as 3.0不分解析xml

public class MoxieAS extends Sprite
{
    public function MoxieAS ()
    {
        var stream:URLStream = new URLStream;
        
        stream.addEventListener(Event.COMPLETE, complete);
        stream.load(new URLRequest("ttt.xml"));  //  <root><a /><b /><c /></root>
    }
   
    private function complete (event:Event):void
    {
        var stream:URLStream = event.target as URLStream;
        var xml:XML = XML(stream.readUTFBytes(stream.bytesAvailable));
        
        trace(xml.*.length());  //  output 3
    }
}

方法二

public class MoxieAS extends Sprite
{
    public function MoxieAS ()
    {
        var loader:URLLoader = new URLLoader(new URLRequest("ttt.xml"));  //  <root><a>测试</a></root> encode by ANSI
        loader.dataFormat = URLLoaderDataFormat.BINARY;
        loader.addEventListener(Event.COMPLETE, complete);
    }
   
    private function complete (event:Event):void
    {
        var BA:ByteArray = new ByteArray;
        BA.writeBytes((event.target as URLLoader).data);
        BA.position = 0;
        
        var xml:XML = XML(BA.readMultiByte(BA.length, "GBK"));
        
        trace(xml.*);  //  output 测试
    }
}

补充:flash教程,As3.0
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,