简体   繁体   English

如何使用Flash As3创建,附加和读取txt文件

[英]How to create, append and read a txt file with flash as3

First off, I am kind of new to Flash and only really know really basic stuff. 首先,我是Flash的新手,只真正了解一些基本知识。

(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. (方案)我已经为我的学校高级高级计算项目在Flash CS3 Professional中制作了一个本地游戏,该游戏几乎完全没有毛刺。 But my teacher says it needs a file handling feature, such as a high score feature in it to make it AH standard. 但是我的老师说,它需要文件处理功能,例如高分功能才能使其成为AH标准。 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. 我想做一个简单的高分功能,它将最终得分,要求用户输入名称,并将其添加到.txt文件中。 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. 由于学校的计算机非常有限,因此我不能使用Adobe AIR或PHP之类的程序,因此我需要使其变得简单。

(Question) So I really need a full tutorial (where to put the coding, layout and everything) to: (问题)所以我真的需要一个完整的教程(将编码,布局和所有内容放在哪里):

  1. Check if there is an existing .txt file called (for example) "High Score.txt" 检查是否存在名为“ High Score.txt”的现有.txt文件(例如)
  2. If there is, load it. 如果有,请加载它。
  3. If not, create a .txt file called (for example) "High Score.txt" to the desktop. 如果没有,请在桌面上创建一个名为(例如)“ High Score.txt”的.txt文件。
  4. Take the users input and place it with their final score after it. 接受用户输入,并将其与最终得分放在其后。
  5. (Optional but not required) Arrange the scores in order of highest to lowest or display the top 5. (可选,但不是必需的)将分数按从高到低的顺序排列或显示前5位。

I will really appreciate it if someone will help me. 如果有人能帮助我,我将非常感激。

Thank you. 谢谢。

Watson. 沃森。

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. SWF通常无法修改本地文件,因为它会打开各种漏洞。 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. 我确信AIR可以通过本地数据库等解决此问题,并且如果您的游戏托管在Web服务器上,则可以使用简单的(不安全的)PHP代理写入文本文件,但是您已经提到这些选项是出来。

An alternative approach which will have the same result: 一种具有相同结果的替代方法:

Use flash.net.SharedObject (check the example code) to store your high scores locally. 使用flash.net.SharedObject (检查示例代码)在本地存储您的高分。 This is a "Flash Cookie" which can be used to store limited amounts of data (Objects, Arrays, etc) on an individual computer. 这是一个“ Flash Cookie”,可用于在单个计算机上存储有限量的数据(对象,数组等)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM