views:

25

answers:

2

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.

A: 

Try something like this and modify to fit your needs:

<?
function FindmyDir($php_self){
$file = explode("/", $php_self);
for( $i = 0; $i < (count($file) - 1); ++$i ) {
$filename2 .= $file[$i].'/';
}
return $filename2;
}
echo FindmyDir($_SERVER['PHP_SELF']);
?> 

You'll also have to strreplace the "/" character or "\".

Codex73
A: 

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

PatrickS