从 FLEX 转换为 PHP
AS3 代码
<fx:Declarations>
<!-- this is the RemoteObject used to make the RPC calls -->
<mx:RemoteObject id="myRemote" destination="MyService" source="MyService"
endpoint="http://localhost/amfphp/gateway.php"
showBusyCursor="true"/>
</fx:Declarations>
protected function button1_clickHandler(event:MouseEvent):void
{
var aut:VOAuthor; // value object class
aut = new VOAuthor();
aut.id_aut = 3;
aut.fname_aut = "test";
aut.lname_aut = "123";
myRemote.saveData(aut);
}
接收 PHP 代码
public function saveData($author)
{
$mysql = mysql_connect("localhost", "mx112", "xxxxxx");
mysql_select_db("flex360");
$query = "INSERT INTO authors (fname_aut, lname_aut) VALUES ('".$author->fname_aut."', '".$author->lname_aut."')";
$result = mysql_query($query);
return $author;
}
<?php
class VOAuthor {
public $id_aut;
public $fname_aut;
public $lname_aut;
var $_explicitType="org.corlan.VOAuthor";}
?>
Flex 网络监视器响应:原始视图
{lname_aut=123, _explicitType=org.corlan.VOAuthor, fname_aut=test, id_aut=3}
,但如果我在 php 代码末尾执行此操作,
return $author->lname_aut;
网络监视器响应为 NULL,
那么问题是我可以打印数组,但如何将数组转换为已知的 php 类型? 5天后,我终于找到了使用amfphp的flex和mysql,有人可以帮忙吗?
AS3 code
<fx:Declarations>
<!-- this is the RemoteObject used to make the RPC calls -->
<mx:RemoteObject id="myRemote" destination="MyService" source="MyService"
endpoint="http://localhost/amfphp/gateway.php"
showBusyCursor="true"/>
</fx:Declarations>
protected function button1_clickHandler(event:MouseEvent):void
{
var aut:VOAuthor; // value object class
aut = new VOAuthor();
aut.id_aut = 3;
aut.fname_aut = "test";
aut.lname_aut = "123";
myRemote.saveData(aut);
}
Receving PHP code
public function saveData($author)
{
$mysql = mysql_connect("localhost", "mx112", "xxxxxx");
mysql_select_db("flex360");
$query = "INSERT INTO authors (fname_aut, lname_aut) VALUES ('".$author->fname_aut."', '".$author->lname_aut."')";
$result = mysql_query($query);
return $author;
}
<?php
class VOAuthor {
public $id_aut;
public $fname_aut;
public $lname_aut;
var $_explicitType="org.corlan.VOAuthor";}
?>
Flex network monitor response : Raw view
{lname_aut=123, _explicitType=org.corlan.VOAuthor, fname_aut=test, id_aut=3}
but If I do this at the end of the php code
return $author->lname_aut;
network monitor response is NULL
so the problem is I can print the array but how to cast tht array to a known php type ?
After 5 days I finnaly figured out flex and mysql using amfphp any one please help ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用 amfphp 和 Flash,则必须注册您的 VO:
只有这样 php 才能识别您从 ActionScript 发送的对象。
if you are using amfphp and Flash you have to register your VOs:
only then does php recognize the objects you're sending it from ActionScript.
是的,您需要注册您的类,另一种方法是在 Flex VO 声明中使用元数据标记。
希望有帮助,
罗杰。
附言。可以在这里找到更详细的解释(对我有帮助):http://www.brentknigge。 com/?q=node/499
Yes you need to register your class, and an alternative is to use the metadata tag in the Flex VO declaration.
Hope that helps,
Roger.
PS. A more detailed explanation (that helped me) can be found here: http://www.brentknigge.com/?q=node/499