我有一個圖像幻燈片程序正在工作,它需要一個硬編碼的圖像數量的文件夾。我想改變它,以便它可以在一個文件夾中,並將顯示所有人,不管數字。有沒有辦法在Flash中執行此操作?我正在想像perl或其他腳本語言中的foreach循環。可以將多個圖像存儲在文本文件中,但我也不知道如何在Flash中讀取圖像。我正在使用actionscript 3.任何幫助將不勝感激。在Flash文件夾中的Foreach文件?
感謝-Mike
我有一個圖像幻燈片程序正在工作,它需要一個硬編碼的圖像數量的文件夾。我想改變它,以便它可以在一個文件夾中,並將顯示所有人,不管數字。有沒有辦法在Flash中執行此操作?我正在想像perl或其他腳本語言中的foreach循環。可以將多個圖像存儲在文本文件中,但我也不知道如何在Flash中讀取圖像。我正在使用actionscript 3.任何幫助將不勝感激。在Flash文件夾中的Foreach文件?
感謝-Mike
@Zarate是正確的,你需要使用服務器端腳本語言。
如果您選擇PHP,請查看readdir
,其中「返回目錄中下一個文件的文件名」。 [PHP Manual]
這裏是我檢索所有文件的文件名在目錄中創建一個PHP類:
class DirectoryContentsHandler
{
private $directory;
private $directoryHandle;
private $dirContents = array();
public function __construct($directory)
{
$this->directory = $directory;
$this->openDirectory();
$this->placeDirFilenamesInArray();
}
public function openDirectory()
{
$this->directoryHandle = opendir($this->directory);
if(!$this->directoryHandle)
{
throw new Exception('opendir() failed in class DirectoryContents at openDirectory().');
}
}
public function placeDirFilenamesInArray()
{
while(false !== ($file = readdir($this->directoryHandle)))
{
if(($file != ".") && ($file != ".."))
{
$this->dirContents[] = $file;
}
}
}
public function getDirFilesAsArray()
{
return $this->dirContents;
}
public function __destruct()
{
closedir($this->directoryHandle);
}
}
這裏是如何使用上面列出的類:
$directoryName = 'some_directory/';
//Instantiate the object and pass the directory's name as an argument
$dirContentsHandler = new DirectoryContentsHandler($directoryName);
//Get the array from the object
$filesArray = $dirContentsHandler->getDirFilesAsArray();
//Display the contents of the array for this example:
var_dump($filesArray);
超越您可以回顯數組的內容並將它們作爲一串變量發送給SWF,或者(如果有大量圖像,這將是更好的選擇)使用PHP創建一個包含文件名的XML文件,然後將該文件發送給SWF。從那裏,使用Actionscript解析XML,加載圖像文件,並將它們顯示在客戶端。
試試這個:
var folder : File = new File('path');
folder.addEventListener(FileListEvent.DIRECTORY_LISTING, dirListHandler);
folder.getDirectoryListingAsync();
--
private function dirListHandler(event : FileListEvent) : void
{
for each(var file : File in event.files)
{
trace(file.url);
}
}
您需要編譯並此AIR應用程序。
HTH
這對我不起作用。這是一個在線Web應用程序,並且該文件夾位於我的服務器上 – msandbot 2010-06-03 19:15:58
Flash是一種客戶端技術,因此如果您的映像位於服務器上,則需要運行服務器端的某些內容。無論是PHP,Ruby,Java,Perl ......無論如何。 只需獲得其中一種語言即可動態編寫XML並將其提供給Flash。 – 2010-06-04 07:22:25