AS3 - AMFPHP connection problems
public
group: Services
gpdinoz@drupal.org - Mon, 2008-06-16 12:57
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


Worked it out
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
This works
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