---
title: "转[]AIR读写外部文件"
author: "AS3"
date: "2011-09-06T22:55:20Z"
tags: []
categories: ["Web前端"]
slug: "air"
draft: false
lastmod: "2011-09-06T22:55:20Z"
id: 1167127
url: "https://as3.iteye.com/blog/1167127"
---

function saveData():void {                
        var _node:XML =<item></item>;
        _node.appendChild (<name>{mc2.name_txt.text}</name>);
        _node.appendChild (<tel>{mc2.tel_txt.text}</tel>);
        _node.appendChild (<number>{mc2.num_txt.text}</number>);
        _node.appendChild (<bogo>{mc2.bogo_txt.text}</bogo>);
        var _v:int=0;
        while(_v<30){
                _node.appendChild (<{"z"+(_v+1)}>{mc1.selected?"√":"×"}</{"z"+(_v+1)}>);                
                _v++;
        }
        xml.appendChild (_node);
                //
        var _fs:FileStream =new FileStream;
        var _f:File =new File(File.applicationDirectory.resolvePath(xmlPath).nativePath);
        _fs.open(_f,FileMode.WRITE);
        _fs.writeMultiByte (xml,"utf-8");
        _fs.close ();
        //
        var _str:String =getTitle();
        for(var _i:int=0;_i<xml.item.length();_i++){
                _str+=getData(xml.item)+"\r\n";
        }
        _fs =new FileStream;
        _f =new File(File.applicationDirectory.resolvePath("data.txt").nativePath);
        _fs.open(_f,FileMode.WRITE);
        _fs.writeMultiByte (_str,"utf-8");
        _fs.close ();
}