我目前正在尝试将一堆高分行从我的网站数据库加载到我的 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/