AS3-获取、创建和保存XML文件
我正在创建一个名为QuizMaker的游戏。AS3-获取、创建和保存XML文件,xml,actionscript-3,file,setter,getter,Xml,Actionscript 3,File,Setter,Getter,我正在创建一个名为QuizMaker的游戏。 游戏的测验是外部的.xml文件,QuizMaker将通过我的类QuizXML导入这些文件。 每个测验都包含带答案的问题,可能是图像形式,也可能是文本形式或其他形式。 玩家应该能够在QuizMaker中导航“我的测验”文件夹。 为此,我需要该文件夹中的文件列表。 下面是未完成的getter函数,以及我的问题:如何获取文件列表 //returns an array of paths to folders and/or .xml files from th
游戏的测验是外部的.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
}
}
谢谢你阅读我的问题。可能就是你想要的
它允许用户浏览文件并将应用程序保存到文件系统
private function save():void
{
var bytes:ByteArray = new ByteArray();
var fileRef:FileReference = new FileReference();
bytes.writeMultiByte("<root>", "iso-8859-1");
//write your xml here
bytes.writeMultiByte("</root>", "iso-8859-1");
fileRef.save(bytes,"savedata.xml");
}
private函数save():void
{
变量字节:ByteArray=newbytearray();
var fileRef:FileReference=newfilereference();
字节。writeMultiByte(“,“iso-8859-1”);
//在这里编写xml
字节。writeMultiByte(“,“iso-8859-1”);
fileRef.save(字节,“savedata.xml”);
}
我们可以安全地假设您使用的是空气吗?