【问题标题】:AS3 / AIR, Generate a .txt file by pressing the save button without dialog boxAS3 / AIR,在没有对话框的情况下按保存按钮生成 .txt 文件
【发布时间】:2017-01-10 08:02:37
【问题描述】:

这是一个通过 Adob​​e Air 部署在 Android 设备中的 Flash 应用程序。我正在尝试将用户的用户名和分数(boxTwo.text + _clickTxt.text)保存在记事本 .txt 文件中,而 android 设备中没有出现任何对话框。一旦按下保存按钮 (btnSave) 就会生成它。我不能让它工作。谢谢!这是我的代码:

import flash.net.FileReference;
import flash.events.Event;

var so:SharedObject = SharedObject.getLocal("Test");
var f:File=new File("path\to\file.txt")
var str:FileStream=new FileStream();

btnSave.addEventListener(MouseEvent.CLICK, onClick);
function onClick(e:MouseEvent):void
{
    so.data.saveData = currentFrame;
    so.flush();

}

btnSave.addEventListener (MouseEvent.CLICK, saveFile)
function saveFile(evt):void
{
    str.open(f, FileMode.WRITE);
    str.writeUTFBytes(boxTwo.text + _clickTxt.text);
    str.close();
}

【问题讨论】:

  • I can't make it work 究竟是什么意思?它会崩溃吗?还是什么?
  • @VladMatvienko 在保存记事本文件之前首先出现一个对话框/确认。它询问记事本文件的位置。我想要的是它会在没有对话框的情况下保存。谢谢!

标签: android actionscript-3 flash air notepad


【解决方案1】:

默认情况下,Adobe Air 不允许将文件写入任何目录 您只能获得对以下内容的写入权限:

  • 文件.documentsDirectory
  • 文件.applicationStorageDirectory
  • “browseForDirectory()”对话框选择的目录

    fileVariable.browseForDirectory("选择一个目录");

(每个平台都有其他特定的目录,但通常它们是这三种类型) 所以只需将路径更改为允许的目录

    var string:String = "Text";
    var file:File = File.documentsDirectory.resolvePath("myTxtFile.txt");
    var stream:FileStream = new FileStream();
    stream.open(file, FileMode.WRITE);
    stream.writeUTFBytes(string);
    stream.close();

【讨论】:

    猜你喜欢
    • 2014-10-08
    • 2015-10-12
    • 2015-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-07
    相关资源
    最近更新 更多