我正在尝试使用AMF PHP将变量传递给flash文件,到目前为止,我看不出我的代码有任何错误,但我几乎没有创建类的经验,所以它是这样的,这是我的代码,
index.php:
<?php
include "amfphp/services/flashMe.php";
$session = true;
if ($session == true) {
$uid = '12345';
$thing = new flashMe;
$thing->push($uid);
} else {
//login
}
?>
flashMe.php:
<?php
class flashMe {
public function __construct() {
}
public function push($one)
{
return $one;//sends the uid to the flash file?
}
}
?>
Flash正在寻找flashMe类和该类中的push方法,但当我运行它时,我的flash文件中的变量总是为空,这段代码有什么问题吗?
提前感谢!
发布于 2010-07-20 03:39:18
您的index.php文件是不必要的。
您的第二个文件不完整。下面是文档中"hello world“类文件的示例:
<?php
class HelloWorld
{
function HelloWorld()
{
$this->methodTable = array
(
"say" => array
(
"access" => "remote",
"description" => "Pings back a message"
)
);
}
function say($sMessage)
{
return 'You said: ' . $sMessage;
}
}
?>
这个文件应该保存为与你在php文件中命名的"HelloWorld“相匹配的”HelloWorld“(你用FlashMe正确地完成了这一部分)。
文档中Flash片段(actionscript格式)的示例文件如下:
import mx.remoting.*;
import mx.rpc.*;
import mx.remoting.debug.NetDebug;
var gatewayUrl:String = "http://localhost/flashservices/gateway.php"
NetDebug.initialize();
var _service:Service = new Service(gatewayUrl, null, 'HelloWorld', null , null);
var pc:PendingCall = _service.say("Hello world!");
pc.responder = new RelayResponder(this, "handleResult", "handleError");
function handleResult(re:ResultEvent)
{
trace('The result is: ' + re.result);
}
function handleError(fe:FaultEvent)
{
trace('There has been an error');
}
网关URL应该指向可以访问您的服务的任何位置。我敢肯定,如果你试几次,你会找到合适的。amfphp的巧妙之处在于,它允许您在尝试在网关中实现您的服务之前对其进行测试(如果您在浏览器中转到URL )。
我也是AMFPHP的新手,但我发现the docs非常有用。如果你需要更多关于类的帮助,你可以在PHP docs page上找到更多信息。
发布于 2010-07-09 22:09:25
你错过了new flashMe
后面的括号
$thing = new flashMe(); $thing->push($uid);
发布于 2010-07-12 10:06:20
Amfphp或Zend AMF只允许您在网关公开的远程类上调用公共方法。您的示例不是类,因此不能调用任何远程方法。这看起来更像是您使用http post所做的事情。
http://framework.zend.com/manual/en/zend.amf.server.html
https://stackoverflow.com/questions/3212607
复制相似问题