AS3 - AMFPHP connection problems

behindthepage's picture

Hi all,

I have been playing around with AS3 and AMFPHP using FlashDevelop IDE and slowly learning. I have pieced the following code together and finally having overcome all the syntax errors and getting the types properly defined It doesn't throw any compiling error however it won't connect.

I get the following error

Error #2044: Unhandled NetStatusEvent:. level=error, code=NetConnection.Call.Failed at drupal2()

If someone could point out my probably obvious mistake I would be very appreciative.

package {
   
   import flash.display.Sprite;   
   import flash.net.NetConnection;
    import flash.net.Responder;
    import flash.text.TextField;
   import flash.text.TextFieldType;

  import flash.events.Event;

   public class drupal2 extends Sprite {
     
       // create, position, and set params on three dynamic text fields: status, node-title, and node-body
       
       private var tf:TextField = createTextField( 10, 0,  200, 200);
     private var ntitle:TextField = createTextField( 11, 50, 200, 200);
     private var nbody:TextField = createTextField( 12, 100, 200, 400);
     private var myService:NetConnection;
       private var responder:Responder;
      
      
       public function drupal2() : void{
         
           responder = new Responder(getData_Result, getData_Fault);
          myService = new NetConnection();
           myService.connect("http://my.domain.com/services/amfphp");
          
           myService.call("node.load", responder , "1");      
          

          // set default status text
         tf.text = "no response from server yet.";            
             
        }
     


     // success result handler
      public function getData_Result( re:Object ):void {
         tf.text = "response:";
           ntitle.htmlText = "<b>Node Title:</b><br/>" + re.result.title;
         nbody.htmlText = "<b>Node Body:</b><br/>" + re.result.body;
        }

     // failure result handler
      public function getData_Fault( fault:Object ):void {
           tf.text = "error";
       }
     
                //Creating Textfield - not sure whether I need this
       private function createTextField(x:Number, y:Number, width:Number, height:Number):TextField {
                       var result:TextField = new TextField();
                       result.x = x; result.y = y;
                       result.width = width; result.height = height;
                       addChild(result);
                      return result;
               }
    }  
}

I don't mind you laughing but please...no shaking of the head.

many thanks
Geoff

Groups:
Login to post comments

Worked it out

behindthepage's picture
behindthepage - Mon, 2008-06-16 13:44

I had the wrong path to amfphp. Boy it is often the silly things that you overlook again and again.

There are a few other mistakes. I will post working code when I have finished.

Geoff


Try just to add custom

apeiron - Sun, 2008-12-07 01:15

Try just to add custom netStatusHandler

private var gatewayUrl:String = "http://localhost/flashservices/gateway.php";
private var myService:NetConnection;
private var responder:Responder;

...

myService = new NetConnection();
myService.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
responder = new Responder(onResult, onFault);
myService.connect(gatewayUrl);

...

public function netStatusHandler(e:NetStatusEvent):void {
trace(e.info.description);
...
}


This works

behindthepage's picture
behindthepage - Wed, 2008-06-18 03:33

This not posted because it is the world's greatest script, rather as correction for my previous post so if someone who has even less knowledge than me stumbles across it they can at least get something that works. I don't know how much time I have wasted working with sample that don't work

package {

         import flash.display.Sprite;
         import flash.net.NetConnection;
         import flash.net.Responder;
         import flash.text.TextField;
         import flash.text.TextFieldType;
         import flash.events.Event;

         public class drupal extends Sprite {

                    // create, position, and set params on three dynamic text fields: status, node-title, and node-body

                   private var tf:TextField = createTextField( 10, 0,  200, 200);
                   private var ntitle:TextField = createTextField( 11, 50, 200, 200);
                   private var nbody:TextField = createTextField( 12, 100, 200, 400);
                   private var myService:NetConnection;
                   private var responder:Responder;

                   public function drupal() : void{

                           responder = new Responder(getData_Result, getData_Fault);
                           myService = new NetConnection();
                           myService.connect("http://www.mydomain.com/services/amfphp");

                           myService.call("node.load", responder , "1");

                           // set default status text
                           tf.text = "no response from server yet.";
 
                  }

                  // success result handler
                  public function getData_Result( re:Object ):void {
                         tf.text = "response:";
                         ntitle.htmlText = "<b>Node Title:</b><br/>" + re.title;
                         nbody.htmlText = "<b>Node Body:</b><br/>" + re.body;
                  }

                 // failure result handler
                 public function getData_Fault( fault:Object ):void {
                         tf.text = "error";
                }

                //Creating Textfield - not sure whether I need this
                private function createTextField(x:Number, y:Number, width:Number, height:Number):TextField {
                       var result:TextField = new TextField();
                       result.x = x; result.y = y;
                       result.width = width; result.height = height;
                       addChild(result);
                      return result;
               }
       }
}

Regards
Geoff


Connection Problems with flash

cameronheikkinen's picture
cameronheikkinen - Tue, 2008-12-02 14:57

I'm currently trying to connect to drupal with flash. I think that my hierarchy with amfphp may be wrong because myService.connect() always gives me an error saying that the url is not found. Any help with this would be much appreciated.


I was having an issue with

raimondious - Fri, 2008-12-05 17:02

I was having an issue with this similar to cameron's and the OP and I finally realized that I hadn't given unauthenticated users access to any of the service modules, so Flash didn't have permission to load anything. It was really odd because it was acting differently depending on my browser - afterward I realized the difference was my session.

Now off to learn about security + the services module...


I'm completely new to drupal,

ventoline - Thu, 2009-10-01 18:08

I'm completely new to drupal, and quite to AS3, so, excuse my questions if they seem basics:

Error #2044: Unhandled NetStatusEvent:. level=error, code=NetConnection.Call.Failed

mmm.. I'm having the same problem, but the url is correct, and i believe the permissions is set properly.. Did anyone find any other reasons for this error?


It is a Permissions problem

needorf - Fri, 2009-10-02 21:56

I had the same problem and realized that is a permissions problem, just give permission to anonymus in service modules. Now my problem is that I get this error:
Access denied.
AMFPHP_RUNTIME_ERROR