I was wondering if it is possible to connect to the the services/amfphp gateway via flash.net.NetConnection. I'm working with AS3 in Flex, but I would like to be able to connect to amfphp without implementing the RPC framework. I have completed the Flex tutorials that use mx.rpc.remoting.RemoteObject so I know that everything is configured correctly. I have successfully connect to the amfphp gateway using gateway.connect("http://localhost/amfphp/gateway.php"); with the following example, but when I change the address to http://localhost/services/amfphp/gateway.php nothing is returned.

I know that the AMFPHP Module overrides some aspects of amfphp, but I'm new to php, and I don't exatly understand the interaction (what is sent to Flex/Flash via services/amfphp and how to call the php Methods).

My ultimate goal is not to work with php files in the amfphp/service folder, but rather with drupal services i.e. node views. I would just like to streamline the actionscript code.

Any and all help will be greatly appreciated.

Thanks,

Kyle

The following example class works with "localhost/amfphp/gateway.php" but not with "localhost/services/amfphp/gateway.php"
Also, I've attempts to call node one using "gateway.call("node.load(1)," are ineffective, am I missing something basic in the method call?

package {
    import flash.display.Sprite;
    import flash.net.NetConnection;
    import flash.net.Responder;

    public class AS3Example extends Sprite {
 
        public var gateway:NetConnection;
       
        public function AS3Example() {
            gateway = new NetConnection();
            gateway.connect("http://localhost/services/amfphp/gateway.php");
            gateway.call("HelloWorld.say", new Responder(onResult, onFault), "say this" );          
        }
       
        public function onResult(responds:Object):void {
            trace ("onResult: " + responds)
        }
       
        public function onFault(responds:Object):void {
                trace("fault " + responds);
        }
    }
}

Comments

JoachimVdH’s picture

Assigned: Unassigned » JoachimVdH
Status: Active » Closed (fixed)

herewith a little sample. This works for me.


package {
	import flash.display.Shape;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.net.NetConnection;
	import flash.net.Responder;
	import flash.text.TextField;
	
	public class AMFPHPTest extends Sprite
	{

		private var gateway:NetConnection;
        private var txt:TextField;
        private var btn:SimpleButton;
      
 		public function AMFPHPTest()
		{
			createSimpleView();
		}
		
        public function init():void {
            gateway = new NetConnection();
            gateway.connect("http://localhost/services/amfphp");
            
            var responder:Responder = new Responder(onResult, onFault);
			
            gateway.call("node.load", responder, 1 );         
        }
      
        public function onResult(responds:Object):void {
            txt.text = "onResult: " + responds.title ;
            reflect(responds);
        }
      
        public function onFault(responds:Object):void {
        	txt.text = "onFault : " +responds.error ;
        	reflect(responds);
        }
        
        public function createSimpleView():void {
        	txt = new TextField();
        	txt.x = txt.y = 10;
			txt.width = 390;
        	txt.height = 200;
			txt.border = true;
			
        	addChild(txt);
        	
        	btn = new SimpleButton();
        	btn.x = 10;
        	btn.y = 220;
        	
			btn.upState = createRectangle( 0x00FF00 );       
			btn.overState = createRectangle( 0xFF0000 ); 
			btn.downState = createRectangle( 0x0000FF ); 
			btn.hitTestState = btn.upState; 
			btn.addEventListener( MouseEvent.CLICK, btnClick );       
        	addChild(btn);     	
        }
        
        private function btnClick(event:MouseEvent):void {
        	init();
    	} 
    	
    	private function createRectangle(color:uint):Shape {       
			var rect:Shape = new Shape(  ); 
			rect.graphics.lineStyle( 1, color ); 
			rect.graphics.beginFill( color ); 
			rect.graphics.drawRect(0,0,150,50)
			rect.graphics.endFill();  
			return rect; 
		} 
		
		private function reflect(obj:Object):void{
			for(var i:String in obj){
				txt.appendText("\n"+i+": "+obj[i]);
			}
		}
	}
}

Patrick Daulie’s picture

Great ! This is the first example that really worked for me. This explains a lot ! Thank you for this.

Do you also have an example how to read only the title and the body with the html tags stripped ?

This is my result in my swf file:

onResult: PAT
data: a:0:{}
sticky: 0
status: 1
title: PAT
format: 1
vid: 1
log: 
body: <p>Body1</p>

comment_count: 0
last_comment_timestamp: 1237562138
promote: 1
yoda-fr’s picture

Hey eldude,
thanks for your exemple, it's very interesting.
It works well for node but I have trouble to display views. When I do

gateway.call("views.get", responder, "pages");

it shows me
onResult: undefined
0: [object Object]
1: [object Object]
2: [object Object]

I tried some things without success.
Can you help me, I am new to as3 and amfphp
Thanks a lot for your help