douyan1613 2010-08-10 18:48
浏览 50
已采纳

AS3没有运行我的PHP脚本

So I am writing this action script program that will call a php file which will return the filenames inside a folder.

My PHP file looks like this

<?php
    $dirname = "thumbs";
    $ret =array();
    if($dir = opendir($dirname)){
        $i=0;
        while($file = readdir($dir)){
            if($file != '.' && $file != '..'){
                $ret["file" . $i] = $file;
                $i++;
            }

        }
        $returnString = http_build_query($ret);
        echo $returnString;
    }

?>

if I just run this by itself I will get

file0=back-matter.pdf&file1=ch1.pdf&file2=ch2.pdf&file3=ch3.pdf&file4=ch4.pdf&file5=ch5.pdf&file6=ch6.pdf&file7=ch7.pdf&file8=ch8.pdf&file9=ch9.pdf&file10=front-matter.pdf

and those are the files inside the thumbs folder. Now I want to call that in my actionscript and be able to get the same output in my action script.

This is my action script file:

package 
{
    import flash.display.MovieClip;
    import flash.display.Loader;
    import flash.net.URLRequest;
    import flash.net.URLLoader;
    import flash.net.URLVariables;
    import flash.net.URLRequestMethod;
    import flash.net.URLLoaderDataFormat;
    import flash.events.Event;

    public class Main extends MovieClip
    {
        public var thumbFolder:String = "thumbs";
        public var markerFolder:String = "marker";
        public var folderGetterPHP:String = "getter.php";

        public function Main()
        {
            var urlRequest:URLRequest = new URLRequest(folderGetterPHP);
            var urlLoader:URLLoader = new URLLoader();

            urlRequest.method = URLRequestMethod.GET;
            urlLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
            urlLoader.addEventListener(Event.COMPLETE, completeHandler);
            urlLoader.load(urlRequest);
        }

        public function completeHandler(evt:Event):void
        {
            trace(evt.target.data);
        }
    }
}

I ran that and I got this

Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.
    at Error$/throwError()
    at flash.net::URLVariables/decode()
    at flash.net::URLVariables()
    at flash.net::URLLoader/onComplete()

I also tried setting

urlLoader.dataFormat = URLLoaderDataFormat.TEXT;

but I only got my php source code displayed as an output. Can someone explain to me how I can get the output of my php to display in flash.

  • 写回答

3条回答 默认 最新

  • douwei1408 2010-08-11 02:06
    关注

    have a look at this class: http://www.as3blog.org/?p=18

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 vc6.0中想运行代码的时候总是提示无法打开文件是怎么回事
  • ¥25 关于##爬虫##的问题,如何解决?:
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题