php - Flash 使用 PHP 和 MySQL 从远程服务器获取数据

标签 php mysql actionscript-3 flash cross-domain

我目前正在尝试将一堆高分行从我的网站数据库加载到我的 Flash 应用程序中。我正在使用 PHP 从 MySQL 数据库检索数据并将其返回到闪存。当我在 Flash Pro 中调试应用程序时,一切正常并且返回数据。

但是,当我发布 swf 并双击它时,它只显示空白屏幕,没有任何反应。当我删除访问 PHP 脚本的代码时,它可以工作,但没有检索到数据。

我在 htdocs 文件夹中添加了 crossdomain.xml。这是xml的内容

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
  <site-control permitted-cross-domain-policies="master-only"/>
  <allow-access-from domain="*"/>
  <allow-http-request-headers-from domain="*" headers="*"/>
</cross-domain-policy>

但还是不行......

感谢任何帮助。 THX b4

最佳答案

您没有提到您正在使用哪个类与 PHP 进行通信...但是无论它是什么类,它也将具有评估失败的方法。查看失败响应。

例如,URLRequest 类可以抛出各种错误,可以捕获这些错误来诊断问题。这是我在 Adobe reference 上找到的一些代码...

The following example creates a new Loader object and passes it a URLRequest object that contains the path to an XML file. If the loading operation is successful, a complete event is dispatched and the data in the XML file traces to the output. Additional event handlers capture other events, including error events.

To run this example, place a file named XMLFile.xml in the same directory as your SWF file.

package {
import flash.display.Sprite;
import flash.events.*;
import flash.net.*;

public class URLRequestExample extends Sprite {
    private var loader:URLLoader;
    
    public function URLRequestExample() {
        loader = new URLLoader();
        configureListeners(loader);

        var request:URLRequest = new URLRequest("XMLFile.xml");
        try {
            loader.load(request);
        } catch (error:Error) {
            trace("Unable to load requested document.");
        }
    }

    private function configureListeners(dispatcher:IEventDispatcher):void {
        dispatcher.addEventListener(Event.COMPLETE, completeHandler);
        dispatcher.addEventListener(Event.OPEN, openHandler);
        dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
        dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
        dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
        dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
    }

    private function completeHandler(event:Event):void {
        var loader:URLLoader = URLLoader(event.target);
        trace("completeHandler: " + loader.data);
    }

    private function openHandler(event:Event):void {
        trace("openHandler: " + event);
    }

    private function progressHandler(event:ProgressEvent):void {
        trace("progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal);
    }

    private function securityErrorHandler(event:SecurityErrorEvent):void {
        trace("securityErrorHandler: " + event);
    }

    private function httpStatusHandler(event:HTTPStatusEvent):void {
        trace("httpStatusHandler: " + event);
    }

    private function ioErrorHandler(event:IOErrorEvent):void {
        trace("ioErrorHandler: " + event);
    }
}
}

更快的方法是简单地打开浏览器的调试控制台(例如,在 Chrome 中,右键单击 > 检查元素 > 控制台选项卡)。查看错误;如果存在安全限制,浏览器也可能会抛出错误。

关于php - Flash 使用 PHP 和 MySQL 从远程服务器获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19767038/

相关文章:

mysql - 如何在 MySQL 查询中定义目标表?

apache-flex - 如何设置 s :BitmapFill dynamically? 的来源(Flash Builder,内部代码)

php - 将成员(member)加入日期/成员(member)成长数据组织成可图形化的 block

java - 在 gradle 多项目 [spring 数据] 中将主题存储库注入(inject) DataService 失败

php - mongodb查询子数组

php脚本选择where语句xcode

actionscript-3 - 将 MX 库包含到 Flash CS5 项目中

javascript - html/javascript 是否等同于 as3/flex?

PHP Javascript 变量帮助

php - 为什么带单引号的字符串在插入数据库时​​会引发错误?