开发者

How to Get 3 Nodes using AS3 and E4X?

开发者 https://www.devze.com 2023-02-28 12:54 出处:网络
I am writing a class in Main.as that makes a urlRequest and returns the result.There are 3 nodes I need, minTemp, maxTemp and Icon. I\'m making the request for one city so there should be just one occ

I am writing a class in Main.as that makes a urlRequest and returns the result. There are 3 nodes I need, minTemp, maxTemp and Icon. I'm making the request for one city so there should be just one occurrence of these nodes. How would I structure the AS3 to grab these nodes and their values?

public class Main extends MovieClip {

public function Main() {

        var urlRequest:URLRequest=new URLRequest("http://myurl");
        var urlLoader:URLLoader=new URLLoader();
        var result:XmlDocument=new XMLDocument();

        urlLoader.addEventListener(Event.COMPLETE, parseXML);
        urlLoader.load(urlRequest);

        result.ignorWhite=true;
        result.parseXML(getXMLString());
        }
}

I'm getting errors 1046 XmlDocument type was not found, 1120 access of undefined property pa开发者_Python百科rseXML, and 1180 call to possibly undefined method getXMLString. How would I clear those up as well?


You did not define the function parseXMl and result is not created either, this way should work:

public class Main extends MovieClip {    
        public function Main() {

                var urlRequest : URLRequest = new URLRequest("http://myurl");
            var urlLoader : URLLoader = new URLLoader();

            urlLoader.addEventListener(Event.COMPLETE, onXmlLoaded);
            urlLoader.load(urlRequest);

        }

        private function onXmlLoaded(event : Event) : void
        {
            XML.ignoreWhitespace= true;
            var urlLoader : URLLoader = event.currentTarget as URLLoader;
            var resultXML : XML = XML(urlLoader.data);
            trace(resultXML);
        }
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消