AMFPHP跟PHP交互的小例子

WBOY
Release: 2016-06-13 13:08:16
Original
922 people have browsed it

AMFPHP和PHP交互的小例子

到这里下载AMFPHP for?FLASH8 的组件,如果你使用其他版本,请到这里选择下载:http://www.adobe.com/products/flashremoting/downloads/components/

下载后安装,完毕后打开Macromedia Flash 8,查看 “窗口|公用库|Remoting”就可以看到AMFPHP的组件了。

新建立一个工程,拖一个RemotingClasses组件到舞台的任何地方,再拖一个List组件,命名为myls,拖一个Button组件,命名为"mybt"
在第一帧的代码行复制以下代码:

import mx.remoting.*;
import mx.rpc.*;
import mx.utils.Delegate;
import mx.remoting.debug.NetDebug;
var gatewayUrl:String = "http://localhost/amfphp/gateway.php";
var service:Service;
NetDebug.initialize();
service = new Service(gatewayUrl, null, "PersonService");
function getPerson() {
    trace("getPerson");
    var pc:PendingCall = service.getPerson();
    pc.responder = new RelayResponder(this, "handleGetPerson");
}
function handleGetPerson(re:ResultEvent) {
    trace("handleGetPerson");
    trace(re.result.getItemAt(0).name);
    _root.mytree.dataProvider = re.result;
    _root.mydg.dataProvider = re.result;
}
function onClick() {
    getPerson();
}
mybt.addEventListener("click", Delegate.create(this, onClick));
Copy after login

在AMFPHP的SERVICES文件夹下新建一个文件,命名为PersonService.php
复制一下内容到PersonService.php

<?php
class PersonService
{
    function PersonService()
    {
        $this->methodTable=array(
            "getPerson"=>
                array(
                   "access"=>"remote"    
                )
        );
        mysql_connect('localhost','root','wuliqunao');
        mysql_select_db('test');
    }
    function getPerson()
    {
         $sql="SELECT * FROM persons";    
         $query=mysql_query($sql);
         return $query;
    }
}
?>
Copy after login

?好了,发布你的程序,单击Button按钮,看到结果:

当然了,你的本机需要有个MYSQL数据有,里面简历一个test数据库,这个库里面创建一个persons数据表,表里2个字段,一个是name,一个是age.(表告诉我,你搞不好这个库啊,搜一个MYSQL数据库入门教程,一下就知道啦。)
好了,大功告成,开始学习AMFPHP之路吧~~~~


php版顶起来--通信教程基础之sendToURL
http://bbs.actionscript3.cn/thread-8144-1-3.html

flash通信教程之URLLoader类1
http://bbs.actionscript3.cn/thread-8230-1-2.html

flash通信教程之URLLoader类2-从后台
http://bbs.actionscript3.cn/thread-8243-1-2.html

flash通信教程URLLoader类3?
http://bbs.actionscript3.cn/thread-8245-1-2.html

flash通信教程URLLoader类4
http://bbs.actionscript3.cn/thread-8246-1-2.html

flash通信教程URLLoader类5-xml?
http://bbs.actionscript3.cn/thread-8247-1-2.html

flash通信教程URLLoader类6
http://bbs.actionscript3.cn/thread-8248-1-2.html

flash通信教程URLLoader类7-request带数据
http://bbs.actionscript3.cn/thread-8249-1-2.html

php与flex互相通信的例子
http://bbs.actionscript3.cn/thread-10726-1-2.html

flash获取php中变量
http://bbs.actionscript3.cn/thread-6494-1-1.html
http://hi.baidu.com/pcbbt/blog/item/4018f64ecb9fa3dbd1c86ac1.html
http://www.51xflash.com/article/flashcs3/200812/14-8057.html
http://www.codehorde.com/thread-1628-1-1.html

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template