5 Replies Latest reply on Aug 10, 2007 2:44 PM by ntsiii

    need help with dataProvider and HTTPService result

    drjfreeze Level 1
      Hi

      I'm following the flickr tutorial at http://labs.adobe.com/technologies/flexbuilder2/tutorials/# and at a stumbling block wrt the HTTPService. The example shows that HTTPService has id="service" and that the 'Find' button calls "service.send()".
      The TileList is used to display the data and the dataProvider="{service.result.rsp.photos.photo}".

      In the example the autocomplete even showed that service did respond to the result message, but
      this is not the case for me. The autocomplete for me only shows "resultFormat" as a possibility. Using
      result, I get the error:

      Access of possibly undefined property result through a reference with static type mx.rpc.http.mxml:HTTPService. flickr1 flickr1.mxml line 11

      Am I missing something?

      Thanks
        • 1. Re: need help with dataProvider and HTTPService result
          TorrenteDev Level 1
          Try "lastResult" instead of result.
          • 2. Re: need help with dataProvider and HTTPService result
            drjfreeze Level 1
            Thanks for that. lastResult is what I was looking for.

            However, now I get the security error trying to visit the url. I think there is some cross-site definition file that needs to be defined, but haven't figured it out yet.

            Anyone know?

            [ faultString="Security error accessing url"
            faultCode="Channel.Security.Error"
            faultDetail="Destination: DefaultHTTP"]
            at mx.rpc::AbstractInvoker/ http://www.adobe.com/2006/flex/mx/internal::faultHandler()
            at mx.rpc::Responder/fault()
            at mx.rpc::AsyncRequest/fault()
            at ::DirectHTTPMessageResponder/securityErrorHandler()
            at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
            at flash.events::EventDispatcher/dispatchEvent()
            at flash.net::URLLoader/flash.net:URLLoader::redirectEvent()

            Thanks
            • 3. Re: need help with dataProvider and HTTPService result
              ntsiii Level 3
              Yes this will require a crossdomain.xml file on the flickr site, or proxying the call through a server. I seem to recall hearing something about flickr and crossdomain, google it.

              Also, I advise against binding directly to lastResult. It is hard to debug, and sooner or later you will need to do some action when the data arrives. Always use a result handler.

              Tracy
              • 4. Re: need help with dataProvider and HTTPService result
                drjfreeze Level 1
                Ok, I'm still working through the Flickr video example and keep turning over stones.
                So far, I have changed

                1) 'result' to 'lastResult'
                2) http://www.flickr.com to http://api.flickr.com to fix the cross-site scripting problem

                Now there is a problem with the dataProvider of the TileList. If I set the dataProvider="{flickrSvc.lastResult}"

                I can see the XML structure with rsp, photos and photo.

                Setting dataProvider="{flickrSvc.lastResult.rsp.photos.photo}" I get nothing. Running in debug mode I get the error message:

                [SWF] Users:jdf:projects:devel:flex:experimentations:flickr1:bin:flickr1-debug.swf - 864,743 bytes after decompression
                warning: unable to bind to property 'rsp' on class 'XML' (class is not an IEventDispatcher)
                warning: unable to bind to property 'photos' on class 'XMLList' (class is not an IEventDispatcher)
                warning: unable to bind to property 'photo' on class 'XMLList' (class is not an IEventDispatcher)

                I found some info online that said to try: dataProvider="{XML(flickrSvc.lastResult.rsp.photos.photo)}"
                but this returns the error:

                TypeError: Error #1088: The markup in the document following the root element must be well-formed.
                at MethodInfo-573()
                at Function/ http://adobe.com/AS3/2006/builtin::apply()
                at mx.binding::Binding/mx.binding:Binding::wrapFunctionCall()
                at mx.binding::Binding/::innerExecute()
                at Function/ http://adobe.com/AS3/2006/builtin::apply()
                at mx.binding::Binding/mx.binding:Binding::wrapFunctionCall()
                at mx.binding::Binding/execute()
                at mx.binding::Binding/watcherFired()
                at mx.binding::Watcher/notifyListeners()
                at mx.binding::PropertyWatcher/eventHandler()
                at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
                at flash.events::EventDispatcher/dispatchEvent()
                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/flash.events:EventDispatcher::dispatchEventFunction()
                at flash.events::EventDispatcher/dispatchEvent()
                at flash.net::URLLoader/flash.net:URLLoader::onComplete()

                I'm not sure where to go from here.
                Can anyone shed some light on getting this demo working?

                Thanks
                • 5. Re: need help with dataProvider and HTTPService result
                  ntsiii Level 3
                  I advise against binding directly to lastResult. It is hard to debug. To fix this you need to know exactly what is in:
                  flickrSvc.lastResult.rsp.photos.photo

                  But you can't with binding. You can in a result handler. Here are some snippets:
                  Tracy
                  Sample code using HTTPService, e4x, handler function to populate a list item.
                  Also shows usage of AsyncToken.

                  The DataGrid tag:
                  <mx:DataGrid id="dg" dataProvider="{_xlcMyListData}" .../>


                  The HTTPService tag:
                  <mx:HTTPService id="service" resultFormat="e4x" result="onResult(event)" fault="..../>

                  Script block declaration:
                  import mx.rpc.Events.ResultEvent;
                  [Bindable]private var _xlcMyListData:XMLListCollection;

                  Invoke send:
                  var oRequest:Object = new Object();
                  oRequest.Arg1 = "value1";
                  var callToken:AsyncToken = service.send(oRequest);
                  token.callId = "myQuery1";

                  Result Handler function:
                  private function onResult(oEvent:ResultEvent):void {
                  var xmlResult:XML = XML(event.result); //converts result Object to XML. can also use "as" operator
                  var xlMyListData:XMLList = xmlResult.myListData; //depends on xml format, is row data
                  _xlcMyListData = new XMLListCollection(xlMyListData); //wrap the XMLList in a collection
                  trace(_xlcMyListData.toXMLString()); //so you can see exactly how to specify dataField or build labelFunction
                  var callToken:AsyncToken = oEvent.token;
                  var sCallId = callToken.callId; //"myQuery1"
                  switch(sCallId) {
                  case "myQuery1":
                  doQuery2();
                  break;
                  ...
                  }
                  }//onResult