【AS3代码】读取外部XML

<LoadingData>
    <question>
        <text>XML!!</text>
        <answers>
            <answer type="correct">correct!!correct!!</answer>
            <answer type="wrong">wrong!!!!wrong!!!!</answer>
        </answers>
    </question>
</LoadingData>

 

package
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    
    public class Main extends Sprite
    {    
        
        public function Main():void
        {
            init();
        }
        private function init():void
        {
            var xmlURL:URLRequest = new URLRequest("LoadingData.xml");
            var xmlLoader:URLLoader = new URLLoader(xmlURL);
            xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
            
        }
        public function xmlLoaded(e:Event):void
        {
            var dataXML = XML(e.target.data);
            trace(dataXML.question.text);
            trace(dataXML.question.answers.answer[0]);
            trace(dataXML.question.answers.answer[0].@type);
        }
    }

posted @ 2012-07-04 11:51  王翔(kingfly)  阅读(2858)  评论(0编辑  收藏  举报