Writing to CSV file in AS3
I have looked far and wide but开发者_如何学JAVA I can't find any resources on how to write to CSV files from flash AS3. I know that flash cannot write to it alone. I have used PHP before to write to a txt file but now I need to open a csv and insert/edit entries that are already in it.
How can I do this?
There is no built in support for CSV, although it can be done manually:
//dummy data
var data:Array = [];
for(var i:int = 0 ; i < 100 ; i++) data[i] = {a:Math.random() * 100,b:Math.random() * 100,c:Math.random()};
//make a csv string
var csv:String = '';
for(i = 0 ; i < 100 ; i++) csv += data[i].a + ',' + data[i].b + ',' + data[i].c+'\n';
//write to disk
stage.doubleClickEnabled = true;
stage.addEventListener(MouseEvent.DOUBLE_CLICK,writeCSV);
function writeCSV(event:MouseEvent) {
var file:FileReference = new FileReference();
var bytes:ByteArray = new ByteArray();
bytes.writeUTFBytes(csv);
file.save(bytes,'test.csv');
}
Still, there is an as3 csv library out there.
I need to open a csv and insert/edit entries that are already in it.
Have a look at Data functions and manipulations on the csvlib wiki.
HTH
精彩评论