我正在创建一个名为 QuizMaker 的游戏。
游戏的测验是外部 .xml 文件,QuizMaker 将通过我的 QuizXML 类导入这些文件。每个测验都包含带有答案的问题,可能是图像形式,可能是文本形式或其他形式。玩家应该能够浏览 QuizMaker 中的“我的测验”文件夹。
为此,我需要该文件夹中的文件列表。
这是未完成的 getter 函数,我的问题是:如何获取文件列表?
//returns an array of paths to folders and/or .xml files from the folder "My Quizzes"
public function getFolders():Array {
var folders:Array = new Array();
//if .xml or a folder is the file looking at, add the file path to folders
return folders;
}
//returns an array of .xml file paths from an array consisting of file paths
//if a folder, which contains .xml files, is encountered from the array, add the .xml file paths to an array
public function getQuizzes(folders:Array):Array {
var validXML:Array = new Array();
for(var curPath:uint=0;folders.length>curPath;curPath++) {
//if folders[curPath] is a folder
//somehow look through the folder's content
//if .xml is the file looking at, add the file path to validXML
//else if .xml is the file looking at, add the file path to validXML
}
return validXML;
}
我的第二个问题是,如何将 XML 文件保存在“我的测验”文件夹中?
这些是未完成的 setter 函数:
//creates new folders inside "My Quizzes" from an array, which contains the folders' names as strings
//if a folder with the same name is encountered, don't override that folder
public function setFolders(folderNames:Array):void {
for(var curPath:uint=0;folderNames.length>curPath;curPath++) {
//if a folder exists as folderNames[curPath]
//do nothing
//else create a folder called folderNames[curPath]
}
}
//creates new .xml files from an array, which contains XML objects, inside a folder from a string
//if an .xml file with the same name as an XML object's nameFile is encountered, don't override that .xml file
public function setQuizzes(outputPath:String,objectsXML:Array):void {
for(var curXML:uint=0;objectsXML.length>curXML;curXML++) {
//if an .xml file exists as objectsXML[curXML].nameFile
//do nothing
//else create objectsXML[curXML] as an .xml file
}
}
感谢您阅读我的问题。