码迷,mamicode.com
首页 > 其他好文 > 详细

简单的as3操作xml

时间:2015-05-29 00:39:32      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:

package  
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    /**
     * ...
     * @author henry
     */
    public class XmlTest extends Sprite
    {
        //全局变量
        private var loader:URLLoader=new URLLoader();
        public function XmlTest() 
        {
            init();
        }
        public function init():void 
        {
            trace("henry wang ");
//            var loader:URLLoader = new URLLoader();
            var url:URLRequest = new URLRequest("test.xml");
            loader.addEventListener(Event.COMPLETE, loadHandler);
            loader.load(url);
        }
        public function loadHandler(e:Event):void
        {
            var myXml = new XML(loader.data);
            //trace(myXml.toString());
            trace(myXml.people[0].role+"love" + myXml.people[1].role);
            var SomeXml:XML=
            <people>
                <role>萧筱</role>
                <actor>何莉</actor>
                <profile>模特</profile>
            </people>;
            myXml.appendChild(SomeXml);
            //trace(myXml.toString());
            trace(myXml.people[4].role+"是默笙大学时代的闺蜜");
            trace(myXml.people[3].role.@id);
            trace(myXml.people.(profile == "CEO").role );
            //trace(myXml.child("people").actor);
            var Some1Xml:XML =
            <people>
                 <role>路人甲</role>
                 <actor>群演</actor>
                 <profile>北京电影学院</profile>
            </people>
            myXml.prependChild(Some1Xml);
            trace(myXml.people.length());
        }
    }

}

 处理xml是as3中常用的技术。

简单的as3操作xml

标签:

原文地址:http://www.cnblogs.com/whlei/p/4537218.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!