php - 如何将 Flash 与 Php 集成

标签 php mysql flash

我想将我的 flash 文件与 php 代码集成。我从

获得了以下代码

http://www.kirupa.com/developer/actionscript/flashphpxml_integration2.htm

function lv(l, n, t, e, f) {
    if (l == undefined) {
        l = new LoadVars();
        l.onLoad = function () {
            var i;
            n.htmlText = "";
            if (t == undefined) {
                n.htmlText += "<b>" + this["title" + e] + "</b><br>";
            } else {
                for (i = 0; i < this.n; i++) {
                    n.htmlText += "<a href='" + this["link" + i] + "'>" + this["title" + i] + "</a><br>";
                }
            }
        };
    }
    l.load(f);
}
lv(sites_txt, "cycle", null, "sites.php");

我执行了该论坛中给出的所有步骤,但在运行该代码时出现错误

1180: Call to a possibly undefined method LoadVars.

Warning: 1060: Migration issue: The method LoadVars is no longer supported.  For more information, see the URLVariables class, the URLRequest.urlVariables and URLRequest.postData properties, and the URLLoader.dataFormat property..

1136: Incorrect number of arguments.  Expected 5.

我是 Flash 脚本的新手,请指导我如何解决这些问题

最佳答案

您的示例代码是在 AS2 中,这里是您如何使用 AS3 使用 PHP 从 PHP 发送和接收数据:

  1. URL请求
  2. URL加载器
  3. URL变量

这是我为您制作的快速类(class):

package
{
    import flash.net.URLRequest;
    import flash.net.URLLoader;
    import flash.net.URLVariables;
    import flash.net.URLRequestMethod;
    import flash.events.Event;

    public class PHPData extends Object
    {
        /**
         * Sends data to a PHP script
         * @param script A URL to the PHP script
         */
        public function send(script:String, vars:URLVariables):void
        {
            var req:URLRequest = new URLRequest(script);

            req.data = vars;
            req.method = URLRequestMethod.POST;

            var loader:URLLoader = new URLLoader();
            loader.load(req);

            // listeners
            loader.addEventListener(Event.COMPLETE, _complete);
        }

        /**
         * Called when a response has been received from a PHP script
         * @param e Event.COMPLETE
         */
        private function _complete(e:Event):void
        {
            var vars:URLVariables = new URLVariables(e.target.data);

            var i:String;
            for(i in vars)
            {
                trace(i + ": " + vars[i]);
            }

            e.target.removeEventListener(Event.COMPLETE, _complete);
        }
    }
}

有了它,您可以将数据以 URLVariables 的格式发送到给定的 PHP 脚本。

URLVariables 很容易像这样准备:

var vars:URLVariables = new URLVariables();

vars.myvar = "some value";
vars.myothervar = 30;

这是我为您模拟的一个简单示例,它向 PHP 发送一个字符串,然后 PHP 发回散列为 MD5 的字符串,并且还附有一个时间戳作为辅助值。

var php:PHPData = new PHPData();

var vars:URLVariables = new URLVariables();
vars.myvar = "marty";

php.send("http://projectavian.com/md5.php", vars);

你的输出类似于:

response: bb3761a33402b4f82806178e79ec5261
time: 1306133172

只需更改 PHPData 类中的 _complete 方法即可根据需要处理您的响应数据:)


我会把它扔进去,因为你的问题有 mysql 标签..

您需要做的就是在 PHP 脚本中进行标准的 INSERT 和 SELECT 查询,并将结果编码为以下格式:

var=1&other=2&more=three

所以你可以..

<?php
    mysql_connect(/* ?? */);
    mysql_select_db(/* ?? */);

    // INSERT example
    $thing = mysql_real_escape_string($_POST["thing"]);
    mysql_query("INSERT INTO table VALUES('','$thing')");

    // SELECT for response
    $id = mysql_real_escape_string($_POST["uid"]);
    $query = mysql_query("SELECT * FROM table WHERE id='$uid' LIMIT 1");

    // send response
    $r = mysql_fetch_assoc($query);
    echo 'fname=' . $r["first_name"] . '&lname=' . $r["last_name"];
?>

关于php - 如何将 Flash 与 Php 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6093285/

相关文章:

php - 我如何在 slim 的框架中定义全局变量

MySQL Workbench 创建前向脚本以错误的顺序删除表,违反外键约束

mysql - 按两列分组并使用不同的值作为 MYSQL 中的列名

javascript - Web 浏览器无法读取 javascript 等。

php - 在电子邮件消息 php 中输出 <hr>

php - codeigniter 中的增量备份

css - sIFR3 中的 "Minimize the Flash movie size by limiting the glyphs embedded in the movie"以提高渲染速度

flash - 如何确定应用程序是作为移动应用程序还是桌面应用程序运行?

php - 带有本地化名称 ID 的友好 URL

javascript - Sequelize 自引用 hasMany 不创建别名函数