获取AS3文件夹中的文件数

获取AS3文件夹中的文件数

问题描述:

I made a flash webpage with a file-upload system for uploading pdf's to a subfolder in the same folder where the swf is hosted. I want to make a very simple system to count the number of files in that folder from inside the AS3 of the main webpage (with the purpose of displaying it somewhere in the flash page..). I still haven't found a straight answer on how to do it (or if it's even possible). I think that maybe i have to use an additional php script to count the files..

Any idea is welcome! Thx in advance!

我制作了一个带有文件上传系统的flash网页,用于将pdf上传到swf所在文件夹中的子文件夹 托管。 我想制作一个非常简单的系统,从主网页的AS3内部计算该文件夹中的文件数量(目的是在flash页面的某处显示它。)。 我还没有找到关于如何做到这一点的直接答案(或者甚至可能)。 我想也许我必须使用额外的PHP脚本来计算文件.. p>

欢迎任何想法! Thx提前! p> div>

You will need a server-side script. For example, using PHP you can use scandir() to read the files and json_encode() to output it as JSON. For example:

// scandir.php
echo json_encode(scandir("path/to/dir"));

Then you simply load the JSON from AS3 using URLLoader. For example:

var urlLoader:URLLoader = new URLLoader(new URLRequest("http://path/to/scandir.php"));
urlLoader.addEventListener(Event.COMPLETE, complete);
function complete(e:Event):void {
        var files:Array = JSON.parse(urlLoader.data);
        trace(files.length);
});