如何使用 flash as3 创建、追加和读取 txt 文件
首先,我对 Flash 有点陌生,只知道非常基本的东西。
(场景)我在 Flash CS3 Professional 中为我的学校高级高等计算项目制作了一个本地游戏,该游戏几乎完全没有故障。但我的老师说它需要一个文件处理功能,例如其中的高分功能,以使其成为 AH 标准。我想制作一个简单的高分功能,它获取最终分数,要求用户输入他们的名字,并将其添加到 .txt 文件中。由于我学校的计算机非常有限,我无法使用 Adobe AIR 或 PHP 或类似的程序,所以我需要它简单。
(问题)所以我真的需要一个完整的教程(在哪里放置编码、布局和所有内容):
- 检查是否存在名为(例如)“High Score.txt”的现有 .txt 文件
- 如果有,则加载它。
- 如果没有,请在桌面上创建一个名为(例如)“High Score.txt”的 .txt 文件。
- 获取用户的输入并将其与最终得分放在一起。
- (可选但非必需)按从高到低的顺序排列分数或显示前 5 名。
如果有人能帮助我,我将非常感激。
谢谢。
沃森.
First off, I am kind of new to Flash and only really know really basic stuff.
(Scenario) I have made a local game in Flash CS3 Professional for my Advanced Higher Computing project for school which is almost completely glitch free. But my teacher says it needs a file handling feature, such as a high score feature in it to make it AH standard. I want to make a simple high score feature where it takes the final score, asks the user to input their name, and add it to a .txt file. Since the computers at my school are very limited, I cannot use programs like Adobe AIR or PHP or anything like that so I need it to be simple.
(Question) So I really need a full tutorial (where to put the coding, layout and everything) to:
- Check if there is an existing .txt file called (for example) "High Score.txt"
- If there is, load it.
- If not, create a .txt file called (for example) "High Score.txt" to the desktop.
- Take the users input and place it with their final score after it.
- (Optional but not required) Arrange the scores in order of highest to lowest or display the top 5.
I will really appreciate it if someone will help me.
Thank you.
Watson.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我很确定由于安全限制,您所要求的是不可能的。 SWF 通常无法修改本地文件,因为这会带来各种漏洞。我确信 AIR 有办法通过本地数据库等解决这个问题,如果您的游戏托管在 Web 服务器上,您可以使用简单的(不安全的)PHP 代理写入文本文件,但您已经提到这些选项是出去。
另一种方法具有相同的结果:
使用 flash.net.SharedObject(查看示例代码)在本地存储您的高分。这是一个“Flash Cookie”,可用于在个人计算机上存储有限数量的数据(对象、数组等)。
I'm pretty sure what you're asking is impossible due to security restraints. SWFs generally can't modify local files since it would open up all sorts of vulnerabilities. I'm sure AIR has ways around this with local DBs and such, and if your game was hosted on a web server you could use a simple (insecure) PHP proxy to write to a text file, but you already mentioned that those options are out.
An alternative approach which will have the same result:
Use flash.net.SharedObject (check the example code) to store your high scores locally. This is a "Flash Cookie" which can be used to store limited amounts of data (Objects, Arrays, etc) on an individual computer.