AS3 - AMFPHP connection problems

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
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

Comments

Worked it out

behindthepage's picture

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

Regards
Geoff
The user previously known as gpdinoz

Try just to add custom

apeiron's picture

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

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

Regards
Geoff
The user previously known as gpdinoz

Connection Problems with flash

cameronheikkinen's picture

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's picture

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's picture

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

bryanhidalgo's picture

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

Try this

rockfer's picture

Hi guys,
I was having the same problem. Hopefully I found a solution to what might be one of the problems with amfphp. I am using a local server for testing purposes. I downloaded amfphp 1.9 and started running a simple test on the connection. I'm using wampserver as my testing server. I looked at the apache logs Apache>Apache error log. And found the following error: '[internal function]: services_server('amfphp')\n#8 C:\wamp\www\sandbox\includes\menu.inc(348): call_user_func_array('services_server', Ar in C:\wamp\www\sandbox\sites\all\modules\amfphp\amfphp\core\amf\app\Gateway.php on line 357, referer: file:///C|/wamp/www/flash/Demo1.swf'

I went ahead and looked at the 'Gateway.php' file on line 357. I found that that the following function was set to 'true':

CODE: SELECT ALL
function disableStandalonePlayer($value = false) {
if($value && $_SERVER['HTTP_USER_AGENT'] == "Shockwave Flash")
{
trigger_error("Standalone Flash player disabled. Update gateway.php to allow these connections", E_USER_ERROR);
die();
}
}

So basically if you change the '$value' to false it will let you make the connection.
As I said I'm a newb so I don't know if this was a no brainer for you guys

Services

Group organizers

Group categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: