duanliu6083 2013-11-04 11:43
浏览 38

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

I'm currently trying to load a bunch of rows of highscores from my website's database to my flash application. I'm using PHP to retrieve the data from MySQL database and return it back to flash. Everything works fine and the data is returned when I'm debugging my application in my Flash Pro.

However, When I published the swf and double click it, it only shows blank screen and nothing happens. When I removed the code which access the PHP script, it works, but no data retrieved.

I've added a crossdomain.xml in my htdocs folder. Here's the content of the 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>

but it's still not working....

any help is appreciated. THX b4

  • 写回答

1条回答 默认 最新

  • duanrang9348 2013-11-06 12:50
    关注

    You did not mention which class you are using to communicate with PHP... but whatever class it is will also have methods for evaluating failures. Look at the failure response.

    For example, the URLRequest class can throw all sorts of Errors which can be caught to diagnose the problem. Here's some code I found on the 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);
        }
    }
    }
    

    A faster approach would be to simply open your browser's debug console (In Chrome for example, right click > Inspect Element > Console tab). Take a look at the errors; the browser may also be throwing an error in the event of a security restriction.

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?