早上好!所以这里是基本代码,我从“使用 Adobe Flash Professional CS5.5 和 Flash Builder 4.5 进行移动开发”教程中获得。几乎是基本代码,但那些混蛋没有提供任何有关 DELETE 功能的信息。这是我第一次申请这个,所以需要帮助!
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
height="494" creationComplete="readFile()">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable] public var todo_items:ArrayCollection;
private function readFile():void
{
var todoFile:File =File.applicationStorageDirectory.resolvePath("todo.txt");
if (todoFile.exists)
{
var fs:FileStream = new FileStream();
fs.open(todoFile, FileMode.READ);
var result:String = fs.readUTFBytes(fs.bytesAvailable);
var items:Array = result.split("\n");
items.pop();
todo_items = new ArrayCollection(items);
fs.close();
}
else { trace("Aplication cant find the file");
}
}
private function writeFile():void
{
var todoFile:File = File.applicationStorageDirectory.resolvePath("todo.txt");
var fs:FileStream = new FileStream();
fs.open(todoFile, FileMode.APPEND);
fs.writeUTFBytes(task_txt.text + "\n");
fs.close();
readFile();
}
private function deleteFile():void
{
//????????????? HEEEEELP !!!!!!!!!!
}
]]>
</fx:Script>
<s:List id="todo_list" left="10" right="10" top="146" bottom="87" dataProvider="{todo_items}"/>
<s:Button left="11" right="10" top="69" height="65" label="Save task" click="writeFile()"
enabled="{task_txt.text.length > 0}"/>
<s:TextInput id="task_txt" left="10" right="10" top="10" height="51" prompt="Specify a task"/>
<s:Button left="10" right="10" bottom="14" label="Delete"
click="todo_items.removeItemAt(todo_list.selectedIndex); deleteFile()"
enabled="{todo_list.selectedIndex != -1}"/>