0 Replies Latest reply on Jun 9, 2010 2:18 PM by andrew.fr

    HTTPService and E4x question (Error #1010)

    andrew.fr

      Hi Folks:

       

      I am new to AIR and I wrote this simple programme to access the Worldcat API. The result has the following structure (abbrevated).

      I want to use E4X to get the name of the first author in the first entry. So I write:

       

      e.result.feed.entry[0].author[0].name

       

      when I run the programme, I get an exception

       

      TypeError: Error #1010: A term is undefined and has no properties.
          at worldcat1/httpServiceResult()
          at flash.events::EventDispatcher/dispatchEventFunction()
          at flash.events::EventDispatcher/dispatchEvent()
          at HTTPOperation/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()
          at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()
          at mx.rpc::Responder/result()
          at mx.rpc::AsyncRequest/acknowledge()
          at DirectHTTPMessageResponder/completeHandler()
          at flash.events::EventDispatcher/dispatchEventFunction()
          at flash.events::EventDispatcher/dispatchEvent()
          at flash.net::URLLoader/onComplete()

       

      I am not sure what I am doing wrong? Any help would be appreciated.

       

      Cheers,

      Andrew

       

      <feed xmlns="http://www.w3.org/2005/Atom" xmlns:URLEncoder="java://java.net.URLEncoder" xmlns:oclcterms="http://purl.org/oclc/terms/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">

        <title>

        <id>

        <updated>

        <subtitle>

        <opensearch:totalResults>

        <link>

        <entry>
          <author>
            <name>Hemingway, Ernest, 1899-1961.</name>
          </author>
          <title>For whom the bell tolls</title>
          <link href="http://worldcat.org/oclc/285606"/>
          <id>http://worldcat.org/oclc/285606</id>
          <updated>2010-03-21T17:55:35Z</updated>
          <dc:identifier>urn:ISBN:7777777777</dc:identifier>
          <dc:identifier>urn:ISBN:9787777777779</dc:identifier>
          <oclcterms:recordIdentifier>285606</oclcterms:recordIdentifier>
        </entry>

        <entry>

      .</entry>

      </feed>

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns="*" creationComplete="hs()">
          <mx:Script>
              <![CDATA[
              import mx.rpc.http.HTTPService;
              import mx.rpc.events.FaultEvent;
              import mx.rpc.events.ResultEvent;
              import mx.controls.Alert;

       

              private function hs():void
              {
                    var myUrl:String;
                    var wcUrl:String;
                    var wskey:String;
                    var query:String;
                    var httpService:HTTPService;

       

                    wcUrl = "http://www.worldcat.org/webservices/catalog/search/opensearch?";
                    wskey = "wskey=""
                    query = "q=civil%20war";

       

                    myUrl = wcUrl + query + "&" + wskey;
                    trace(myUrl);

       

                    httpService = new HTTPService();
                    httpService.resultFormat = "e4x";
                    httpService.url = myUrl;
                    httpService.request = "GET";
                    httpService.showBusyCursor = true;
                    httpService.addEventListener(ResultEvent.RESULT, httpServiceResult);
                    httpService.addEventListener(FaultEvent.FAULT, httpServiceFault);
                    httpService.send();
              }

       

              public function httpServiceResult(e:ResultEvent):void
              {
                   //var result:XML;
                   trace(e.result.feed.entry[0].author[0].name.toString());
                   //mx.controls.Alert.show(e.result.feed.entry[0].author.name.toString());
                   //mx.controls.Alert.show(e.message.body.toString());
              }

       

              public function httpServiceFault(e:FaultEvent):void
              {
                   mx.controls.Alert.show(e.toString());
              }
              ]]>
          </mx:Script>
      </mx:WindowedApplication>