存档

文章标签 ‘amfphp’

在flash 9中连接Amfphp

2008年3月9日 评论已被关闭

import flash.net.*;
var nc:NetConnection=new NetConnection();
nc.objectEncoding=0;
nc.connect("http://localhost/amfphp/gateway.php");
nc.call("HelloWorld.say", new Responder(ons, onf), "9999999999999999999999999999");
//方法名称,返回侦听,参数
function ons(r:Object) {
    //正确返回数据
    trace(r);
}
function onf(r) {
    //错误
    for(var i in r){trace(i+"-"+r[i])}
}

分类: 未分类 标签:

amfphp的问题汇总

2007年9月23日 评论已被关闭

下面的问题都是在我在实际操作中碰到的一些问题:

在browser中可以看到类名,点击可就是出错(如图),最后发现问题在php文件的编码问题上。

还有一个问题是出现在类的名称上。哎!!!!!!!
image

 

又来了一个问题,无返回状态:
php中的代码:

function gea(){
return "!!!!";
}

在flash中remoting时用service.gea 无返回成功提示,一定要写成带参数的形式:gea(”),带了一个空字符串,这样就返回成功了

分类: 未分类 标签: ,

Remoting开始教程

2007年9月23日 评论已被关闭

(备注:此教程根据原英文教程"翻译"而来,只供个人学习时使用,翻译的质量有限,能看就凑合着看吧,大概的意思都表现出来了)

Remoting在开始可能有一点的难使用,无论如何,在你使用它一段时间后,它会变为非常的简单自然。

当在flash中开始一个Remoting工程的时候,开始打开windows->common Libraries->Reomoting,然后拖 RemotingClasses和RemotingDebugClasses 到舞台上。第二步是开始 NetConnection debugger 通过在第一帧上插入以下的代码或者你的主类初始函数中:

import mx.remoting.debug.NetDebug;
    import mx.remoting.*; 

import mx.rpc.*; 

NetDebug.initialize();

Remoting依赖在你的每个新帧或者类中使用这组导入的语句,否则当你尝试编译的时候会告诉你不能找到类。

下步是建立服务。Service构造函数有5个参数,在大多数场合下,你将只需要指定前面三个,第一个是网关的地址,第二个通常是null,第三个是service的位置:

var service:Service = new Service
    ('http://localhost/amfphp/gateway.php', null, 

'com.company.MyService');

这将会连结到你的网关和查找 services文件夹中的com/company/MyService.php 文件。这个文件必须有一个类叫 MyService,定义了 一个methodTable成员(详细资料在下面)。

你可以重新使用同样的service 来调用不同的方法。实际中,大多数的人都喜欢放置他们的service在一个类中,作为一个静态的变量或者单独的来访问。

一旦Service被建立,就开始调用远程方法了:

var pc:PendingCall = service.myMethod("arg1", {x:'myX'});
    pc.responder:RelayResponder = 

new RelayResponder(this, "onSuccess", "onFault");

为了调用一个方法,你一开始调用它好像它是一个本地服务一样,你将会接收到一个 pending call。在远程服务器上,myMethod 方法在MyService类中,如果它在methodTable中被定义为一个 remote函数(详细资料在下一页)

然后你使用一个RelayResponder来设置返回,远程方法将会在下一帧自动被调用。如果这个方法工作了,onSuccess会被调用,而onFault不会,onFault不会捕捉超时,忽略网关或者不幸的错误(NetConnection.Call.BadVersion),只有逻辑错误会被触发,程序员通过exceptions(PHP5)或者trigger_error (PHP4,然后E_USER_ERROR 和较少的critical errors 会被报告)。

The Relay class 工作类似RelayResponder,但是使用references代替字符串,意思是:如果你忽略返回的类型,你会获得一个编译错误。

现在你需要设置responders:

function onSuccess(re:ResultEvent) {
  trace("Success!"); 

NetDebug.trace(re.result); } 
function onFault() {
  trace("Fudge! :("); }

成功返回的结果是第一个参数.result。因此可以使用 re.result。这个结果是一个本土的Flash格式(字符,数字,数组,对像等等)。

mx.remoting.RecordSet

到现在为止,你已经看到了怎么样调用远程方法和接收返回来的数据。到如今你知道它是可笑地使用Remoting简单的调用一个远程方法带有复杂参数。无论如何,最引起兴趣地功能是Remoting的结果集操作。

如果你从你的远程方法中发送回来一个结果集(返回:mysql_query("SELECT * FROM myTable");),这个结果将会是一个mx.remoting.RecordSet的实例。这是一个特别的类,它有大量的好处,有用的方法:

  • getItemAt(index) and removeItemAt(index)
  • 通过自定义函数过滤(过滤方法)
  • 通过自定义函数排序 (排序方法)
  • 事件派遣

如果那还不够,MM的 V2组件打算使用Recordsets作为dataProviders 例如:如果你有一个datagrid在舞台,如果你设置它的dataProvider为你的结果,它将会显示 headers和 columns和rows,允许不同的列排序。对单独的一行代码,有许多功能。把它们放在一起:

import mx.remoting.debug.NetDebug;
    import mx.remoting.*; 

import mx.rpc.*; 

NetDebug.initialize(); 

var service:Service = new Service 

('http://localhost/amfphp/gateway.php', null, 

'com.company.MyService'); 

var pc:PendingCall = service.myService("arg1", {x:'myX'}); 

pc.responder:RelayResponder = new RelayResponder(this, 

"onSuccess", "onFault"); 
function onSuccess(re:ResultEvent) {
    var rs:RecordSet = RecordSet(re.result); 

myDatagrid.dataProvider = rs; }
function onFault() {
    trace("Fudge! :("); }

Remoting有许多的其它功能,也同样喜欢鉴定和web service 消费,但是你可以马上看到就像前面的你可以实现许多功能,比LoadVars和XML更自然。


分类: 未分类 标签: ,

AMFPHP 1.2中更新了什么

2007年9月22日 评论已被关闭
(备注:此教程根据原英文教程"翻译"而来,只供个人学习时使用,翻译的质量有限,能看就凑合着看吧,大概的意思都表现出来了)
AMFPHP 1.2有什么新的东西

Amfphp 1.2 建立在amfphp 1.0 和短期的1.1版本基础上,它有以下的新的特性:

增强服务浏览

服务浏览现在可以在客户端上使用模似请求。意思就是:你不需要安装Flash就可以测试出你的服务,它对各种团队使用amfphp非常简单。测试速度也快了,代码产生被提高,支持ARP框架和自动保存。

新的文件夹结构

新的文件夹结构混乱会比较小,导航比较简单,不同版本的amfphp之间移植

提高类的映射

Amfphp now features complete class mapping options from the gateway.

What’s new in AMFPHP 1.0

A lot has changed since AMFPHP’s last version 0.9b. We’ve switched to a better engine, which allows us to add some much-wanted functionality. Here’s an outline of what’s new:

New engine

The core of the new engine was written by Justin Watkins, and was created to be 100% object oriented, secure, and reliable. Each step of the interpretation of AMF messages is carried through two chains: filters and actions. Expanding the capabilities of AMFPHP is as simple of creating a new filter or action, and modifying the chain in the right spot.

Enhanced support for different charsets

Flash uses Unicode, while PHP natively uses latin1 (ISO-8859-1). We’ve solved the babel tower by adding transparent support for charset transcoding using iconv, meaning you can work in your native language and charset, by calling the appropriate method in your gateway.php file.

Faster serialization

AMFPHP is renowned to be fast, and we’ve made it even faster by squeezing every bit of power from PHP in this new release. We’ve tightened the serializer and tweaked it for large resultsets; sending a resultset with 5 fields and 400 rows takes about 80% less time it used to. We’ve also tamed its memory usage, meaning it can be easily deployed on high-traffic servers.

Less NetConnection.Call.BadVersion error

The new loose mode sets up an output buffer to suppress echo, print and other calls to functions that output to the client to protect you from yourself. This should eliminate a good half of the common causes for the dreaded NetConnection.BadVersion error.

远程追踪

我们添加了一个新的NetDebug::输出静态方法就像在AS中的NetDebug.trace功能一样,但是它是远程工作的,它可以用到任何自定义的服务类。

Pageable recordsets

Pageable recordsets allow you to send back SQL resultsets in chunks. On the Flash side of things, Macromedia’s classes handle synchronization between the client and server and the functionality is already plugged into the data grid, meaning it is easy to work with large recordsets.

Class mapping

AMFPHP now allows mapping objects in method arguments to custom PHP classes. To use this feature all you need to do is set the type under the arguments in the method table.

Tighter integration into the service browser panel

The new version is compatible with both Macromedia’s service browser, and Muzak’s new (and better) panel. We’d like to thank Muzak who furnished the technical details on how we could achieve this.

HTML-based service browser

We’ve created our own HTML-based browser that features, in addition to service description, automatic Actionscript generation (scaffolding). That’s right, save time by browsing to your service and copy-pasting the code generated for you in Flash. Both AS2 (using the Service class) and AS1 (using NetServices.as) are generated. With a little bit of JavaDoc you can get it to generate your methodTable as well.

Tighter integration into the NetConnection Debugger

We’ve added support for new events in the NetConnection debugger, which means more verbose debugging output, which should help you figure what is going on between Flash and PHP.

Cookieless sessions

AMFPHP automatically handles sessions for you and sends back a header to Flash with a redirect to the gateway with the PHPSESSID appended to the query, meaning cookieless sessions are supported.

Authentication

Well, not really new, but it works more smoothly now because of the aforementioned cookie less sessions.

PHP5 compatibility

We’ve fixed incompatibility issues with PHP5 caused by its new pass-by-ref mechanism for class instances.

PHP5 exception support

You can now throw your own exceptions inside of your services and they will be sent back to Flash automatically in the onStatus handler.

Soap Client support

The native PHP5 SOAP extension is supported for web services, and it is much faster than NuSOAP and PEAR::SOAP alternatives.

More databases supported

SQLite, MySQLi, Oracle (oci8), Frontbase, Pear::db and PDO added to the roster of AMFPHP-compatible databases.

Transparent client header support

You can now use the Headers::getHeader($key) function anywhere in your services to get a client header by key.

FlashComm and SSL support

New headers are being sent by AMFPHP for compatibility with FlashComm and SSL.

支持新的返回类型

返回的类型可以是:二进制,原始,数组,structof, 和更多的为专门的程序。也添加了一个新的 methodTable 选项

fastArray is implemented for faster array handling for large multi-dimensional arrays.

 

New gateway options for deployment

disableStandalonePlayer(), disableServiceDescription(), disableTrace() and disableDebug() methods available for more secure deployement.

简单的安装和较好的文档

我们相信 AMFPHP是好的,它应被蔓延到全世界,新的文档和简单的安装程序应该可以帮助你从零开始。

A bunch of bug fixes

We’ve searched high and low and corrected FlashComm compatibility issues, authentication issues, problems with corrupted AMF messages and more.

分类: 未分类 标签: ,

Amfphp手册

2007年9月22日 评论已被关闭
(备注:此教程根据原英文教程"翻译"而来,只供个人学习时使用,翻译的质量有限,能看就凑合着看吧,大概的意思都表现出来了)
Amfphp手册

Amfphp是一个php的RPC工具包,它允许无缝的与PHP通讯:

1.flash 和 flex Remoting
2.JavaScript 和 Ajax与JSON
3.XML客户端与XML-PRC

什么是RPC

PRC(远程程序呼叫)是一种客户端与服务器之间数据的通讯。你调用一个方法在一个本地对像与多种多样的参数,设置一个返回,接收一个结果。你不用担心你要怎么要发送和接收数据。实施细则正在走抽象,所以它看起来好像你通话本地方法。

在后台它是怎么工作的

服务器和客户端,暂时称呼 PHP 和 Flash ,对描述调用方法和复杂数据达成了一致协议。客户端串行请求和发送到网关。 Amfphp然后自动:

1.Deserializes请求
2.查找相应的远程类
3.实例化类
4.完成安全检查
5.调用远程方法,使用指定的参数
6.连续返回数据

Amfphp 可以完全地连续和deserialize复杂类型。除对像和数组之外,它还支持从数据库连结的资源,也就是说你可以简单的从你的远程方法中返回 mysql_query和amfphp将会知道该对它做什么。如果平台支持它(通常的,只有Flash Remoting) ,它可以操作循环引用和对像类型。它也支持简单地远程调试。最终,amfphp 与浏览器服务一起发生,允许你测试您服务之前创建一个前端。

分类: 未分类 标签: ,