Export Flash Builder As3 arrayCollection as csv in the AC original order.

aduvall
aduvall used Ask the Experts™
on
I have an ArrayCollection that I am trying to save to a folder on a web server to csv.

I don't mind using a combination of AS3 and PHP to accomplish this. I tried first sending the data as XML to a php script (magicparser) and then converting it to CSV but I could not get it to work as the csv was not in the order that it was originally in the ArrayCollection. I would like to know how to get this in it's proper order.

 If the CSV can be generated from Flex then auto uploaded to the server for further processing that would be fine as well.


This is how the CSV file should look
H,TUS test,TUS test,02/8/2012,TUS test,1234567890,555,05/19,Visa,
D,MBE37602SH,MBE37602SH,4,EA,54.41,345678,2/8/2012,,
D,MBE37602SH,MBE37602SH,4,EA,54.41,345678,2/8/2012,,

This is what I get


   ,TUS TEST,05/19,Visa,,TUS TEST,555,1234567890,02/8/2012,H,TUS test
  ,MBE37602SH,2/8/2012,,,MBE37602SH,345678,54.41,4,D,EA
 ,MBE37602SH,2/8/2012,,,MBE37602SH,345678,54.41,4,D,EA

This is the ArrayCollection

private var items:ArrayCollection = new ArrayCollection([
{type:"H", cnum:"TUS TEST", fg:"TUS TEST", qty:"02/8/2012", uom:"TUS test", price:"1234567890", po:"555", ddate:"05/19", efield:"Visa", ffield:""},
{type: "D", cnum:"MBE37602SH", fg:"MBE37602SH", qty:"4", uom:"EA", price:"54.41", po:"345678", ddate:"2/8/2012", efield:"", ffield:""},
{type: "D", cnum:"MBE37602SH", fg:"MBE37602SH", qty:"4", uom:"EA", price:"54.41", po:"345678", ddate:"2/8/2012", efield:"", ffield:""}]);
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2011
Commented:
I am parse-ring CSV to Array using Reg Exp

public static const CSV_REG_EXP:RegExp = new RegExp(/,(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))/);

The first you need to convert string to lines

var lines:Array = str.split('\n');

Here is how I am getting rows

var rows:Array = [];

//Replace rows string to array
for(var r:uint = 0; r < lines.length; r++){
    var line:String = String(lines[r]).replace('\r', ''); //remove on Windows OS "END LINE" return character
   if(line != null && line.length > 0)
      rows.push(line.split(CSV_REG_EXP));
}


I hope it will work for you

Author

Commented:
This solution worked well for me.  Thank You

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial