繁体   English   中英

尝试使用 URLLoader 获取数据时我做错了什么?

[英]What am I doing wrong trying to get data with URLLoader?

嘿,我有一个 php 文档动态生成以下内容:

peerID=e224d6cac76ef3181d4804858d82ebeee7e67ad7bdd7b02f3857a700b0ec7fbc

(来自 get_peerID.php)我正在使用以下 AS3 来尝试获取这些数据:

private var myLoader:URLLoader = new URLLoader();    
private function sendData():void {
                writeText("sending data...");
                var objSend:Object = new Object;
                objSend.peerID = myID.text;
                put_peerID.send( objSend );
                writeText("http://localhost/example.com/scripts/get_peerID.php?peerID=" + myID.text);
                var myRequest:URLRequest = new URLRequest("http://localhost/example.com/scripts/get_peerID.php?peerID=" + myID.text);
                myRequest.contentType = "text/plain"; 
                //var myLoader:URLLoader = new URLLoader();
                myLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
                configureListeners(myLoader); //.addEventListener(Event.COMPLETE,onComplete);
                myLoader.load(myRequest);


            }

            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 {                
                writeText("completeHandler: " + myLoader.data.peerID);
            }

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

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

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

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

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

生成以下文本(来自writeText() ):

 sending data...
http://localhost/example.com/scripts/get_peerID.php?peerID=5131079b60ba3ae05f9d54568896db1e04f772f97bb98c6d525cb8ba3032798b
openHandler: [Event type="open" bubbles=false cancelable=false eventPhase=2]
httpStatusHandler: [HTTPStatusEvent type="httpStatus" bubbles=false cancelable=false eventPhase=2 status=200 responseURL=null]

所以,它没有给我我需要的数据。 我不确定下一步该尝试什么。 我整天都在论坛里进进出出,所以任何帮助都将不胜感激。

它不起作用,因为我在本地主机上运行它。 Adobe 说:对于 Flash Player 8 及更高版本:

  • 如果调用文件在本地文件系统沙箱中并且目标资源来自网络沙箱,则不允许数据加载。
  • 如果调用文件来自网络沙箱并且目标资源是本地的,则也不允许数据加载。

发布并放到网上后,它就可以工作了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM