【发布时间】:2011-12-27 11:50:48
【问题描述】:
我在 StackExchange 中找不到一个好的、清晰的问题和答案,所以我会尽可能清楚地提出这个问题,并希望得到一个清晰、简洁的答案。
假设我有一个 .txt* 文件,其中包含我要加载到 ActionScript 3 程序中的一类对象的变量。我可以使用如下导入语句:
[Embed(source="test.txt",mimeType="application/octet-stream")]
private var testFile:Class;
对于一些我需要这样做的地方,但我还需要知道用户从本地硬盘驱动器选择的文件有何不同。
在代码中,如何将此文件testFile:Class 转换为字符串数组result:Array?
*:如果您有使用.xml 或其他格式的解决方案,还请提供文件内容的示例以及如何将它们放入 AS3 中的变量中
编辑:下面是我整理的一个快速示例文件,test.txt:
testing
1
2
3
4
5
testing
6
7
8
9
10
我目前必须尝试将其作为字符串导入的代码(然后我可以使用 string.split("\n") 将其转换为数组)......这会产生一个空字符串而不是以上:
var fileContent:String = new textFile() as String;
trace(fileContent); // Trace comes back with "null" and
// the next line crashes my program for a null reference.
var result:Array = fileContent.split('\n');
【问题讨论】:
标签: flash actionscript-3 actionscript flixel