2 Replies Latest reply on Feb 14, 2010 5:46 AM by fakerabbit

    Flex and amfphp - works on browser but not in the app

    fakerabbit

      Hello there!

       

      I'm working on an application that works as a html file manager. At some point I want to get the metadata of a selected page and I want to use amfphp to do this. My php function in services works fine, when I launch it in service browser, it gives me something like this:

       

      (Object)#0
        description = "The website of digital artist Enayla."
        keywords = "enayla, digital art, furiae, ebonykeep, ek, art forum, digital artist"
        title = "Tytul"

       

      And it's all great, but when I try to launch the same thing from my application it doesn't seem to work. Here's the simplified code:

       

           private function fileRowSelect(event:flash.events.Event):void{
                if(!ncDB.connected){
                     ncDB.connect(adres + "admin/amfphp/gateway.php");
                }
                ncDB.call("admin.getMenuTags", new Responder(handleGetMenuTags, onFault), event.currentTarget.selectedItem["path"]);
           }

       

           private function handleGetMenuTags(result:Object):void{
                if (result==null){
                     return;
                }else{
                     descTag.text = result.description;
                     keywordsTag.text = result.keywords;
                     titleTag.text = result.title;
                } 

           }

       

           private function onFault(fault:String):void{
                     error.text=fault;
           }

       

           The "onFault" function is called and the error text is [object Object]. Can anyone tell me what am I doing wrong here? That's not the first time I'm using amfphp and I've never had such problems. Thanks in advance for any help

        • 1. Re: Flex and amfphp - works on browser but not in the app
          archemedia Level 4

          What is ncDB? Is it a remote object?

           

          Remote object don't have a connect method. Istead you should set the endpoint, source and destination properties.

           

          If you handle your requests through AS3, you could do the following. I use this code in a singleton class.

           

          in the constructor:

           

          ws.RemoteObject = new RemoteObject();

          ws.destination = "amfphp";

          ws.source = "nameOfYourService";

          ws.endPoint = "linkToYourGateway.php";

          ws.addEventListener(FaultEvent.FAULT, this.faultHandler);

           

          In a method named 'call':

           

          public function call(endPoint:String = null, serviceMethod:String, resultFunction:Function = null, ...args):void
                  {

           

                    if (endPoint != null)

                         ws.endPoint = endPoint;


                      if (resultFunction == null)
                      {
                          resultFunction = defaultResult;
                      }
                     
                      if (ws.operations.hasOwnProperty(serviceMethod))
                      {
                          ws[serviceMethod].removeEventListener(ResultEvent.RESULT, resultFunction);
                          ws[serviceMethod].removeEventListener(ResultEvent.RESULT, defaultResult);
                      }
                     
                      ws[serviceMethod].addEventListener(ResultEvent.RESULT, resultFunction);
                      ws[serviceMethod].arguments = args;
                      ws[serviceMethod].send();
                  }

           

          Does this help?

           

          Dany

          1 person found this helpful
          • 2. Re: Flex and amfphp - works on browser but not in the app
            fakerabbit Level 1

            Thanks a lot for the reply! I must say I didn't really understand the code you provided, but I searched the web and I used http://sujitreddyg.wordpress.com/2008/09/04/invoking-php-functions-from-flex-using-amfphp/ to make it work with a remote object. Now it seems to work fine, but I wonder what I did wrong the last time. The ncDB that you were asking about was a netConnection, and I'm pretty sure this is also a right way to do this, as I still use my applications that use netConnection and amfphp to work with mySQL database.

            Thanks for help and I think the problem is solved, although I wouldn't mind if someone told me where did I go wrong in my previous attempt