【问题标题】:AS3 / AIR - Creating a plain text file?AS3 / AIR - 创建纯文本文件?
【发布时间】:2011-04-18 21:37:52
【问题描述】:

是否可以使用 AS3 或 AIR 创建纯文本文件?

示例:我想创建一个名为“MyTextFile.txt”的纯文本文件,让它包含“这是我的文本文件”的文本。并将其保存到我的桌面。

另一种选择是让文件已经存在于目录中,所以我只需要重写它的内容 - 假设这样会更容易。

所有这些都应该作为后台进程发生,不会出现任何保存对话框面板。

【问题讨论】:

    标签: actionscript-3 file air plaintext


    【解决方案1】:
    var file:File = File.desktopDirectory.resolvePath("MyTextFile.txt");
    var stream:FileStream = new FileStream();
    stream.open(file, FileMode.WRITE);
    stream.writeUTFBytes("This is my text file.");
    stream.close();
    

    【讨论】:

      【解决方案2】:

      我知道这是一篇旧帖子,但请考虑以下从输入文本字段的文本创建一个新的 .txt 文件。

      var tf:TextField;
      var fileRef:FileReference;
      
      function saveFile(evt):void
      {
      fileRef = new FileReference();
      fileRef.save(tf.text, "saveFile.txt");
      }
      

      【讨论】:

        【解决方案3】:

        同时考虑这个文本:

        Text fields instead of trace statements

        在移动设备上运行时,您看不到跟踪语句的输出。

        函数 createTracingTextField(x:Number, y:Number, 宽度:数字,高度:数字):TextField {

        var tracingTF:TextField = new TextField(); 
        tracingTF.x = x; 
        tracingTF.y = y; 
        tracingTF.width = width; 
        tracingTF.height = height; 
        
        // A border lets you more easily see the area the text field covers. 
        tracingTF.border = true; 
        // Left justifying means that the right side of the text field is automatically 
        // resized if a line of text is wider than the width of the text field. 
        // The bottom is also automatically resized if the number of lines of text 
        // exceed the length of the text field. 
        tracingTF.autoSize = TextFieldAutoSize.LEFT; 
        
        // Use a text size that works well on the device. 
        var myFormat:TextFormat = new TextFormat(); 
        myFormat.size = 18; 
        tracingTF.defaultTextFormat = myFormat; 
        
        addChild(tracingTF); 
        return tracingTF; 
        

        }

        等等……

        【讨论】:

          猜你喜欢
          • 2013-02-20
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-11-12
          • 2012-12-13
          • 2013-03-01
          • 2012-05-25
          • 2020-05-08
          相关资源
          最近更新 更多