maxou
10.04.2008, 15:50
Hi everybody,
Sorry if this thread is a clone but i haven't found similar subject here.
Here is my little problem:
I need to extract cell content from a csv file in flash. So i found that code
var temp = new LoadVars();
var theFileObj = new LoadVars();
var theFile =
temp.sendAndLoad("http://mydomain.com/sample2.csv,theFileObj,GET");
theFileObj.onData = function(src) {
var myDataProvider = new Array();
var theFileArray = src.split("\r\n");
var theFieldNames = theFileArray[0].split(",");
var numberOfFields = theFieldNames.length;
for(var j=0; j<numberOfFields; j++) {
theFieldNames[j] = removeQuotes(theFieldNames[j]);
}
var tempArray;
var tempObj;
for(var i=1; i<theFileArray.length; i++) {
tempArray = theFileArray[i].split(",");
tempObj = new Object();
for(var ii=0; ii<numberOfFields; ii++) {
tempObj[theFieldNames[ii]] = removeQuotes(tempArray[ii]);
}
myDataProvider.push(tempObj);
}
myGrid.setDataProvider(myDataProvider);
}
function removeQuotes(theString) {
if(theString.charAt(0) == '"' || theString.charAt(0) == "'") {
return theString.substr(1, theString.length - 2);
}else{
return theString;
}
}which is supposed to parse the csv thanks to ";" separations.
But the problem is i can't get a word about Dataprovider ! I'm not a pro in action script coding and the only thing i want is to put each content of each cell of the csv in separate variables ( i.e.: var content1 = Array[1]; ). My csv has the following structure: 8 rows and 3 columns.
Does someone could help me please ?
Thank you
Sorry if this thread is a clone but i haven't found similar subject here.
Here is my little problem:
I need to extract cell content from a csv file in flash. So i found that code
var temp = new LoadVars();
var theFileObj = new LoadVars();
var theFile =
temp.sendAndLoad("http://mydomain.com/sample2.csv,theFileObj,GET");
theFileObj.onData = function(src) {
var myDataProvider = new Array();
var theFileArray = src.split("\r\n");
var theFieldNames = theFileArray[0].split(",");
var numberOfFields = theFieldNames.length;
for(var j=0; j<numberOfFields; j++) {
theFieldNames[j] = removeQuotes(theFieldNames[j]);
}
var tempArray;
var tempObj;
for(var i=1; i<theFileArray.length; i++) {
tempArray = theFileArray[i].split(",");
tempObj = new Object();
for(var ii=0; ii<numberOfFields; ii++) {
tempObj[theFieldNames[ii]] = removeQuotes(tempArray[ii]);
}
myDataProvider.push(tempObj);
}
myGrid.setDataProvider(myDataProvider);
}
function removeQuotes(theString) {
if(theString.charAt(0) == '"' || theString.charAt(0) == "'") {
return theString.substr(1, theString.length - 2);
}else{
return theString;
}
}which is supposed to parse the csv thanks to ";" separations.
But the problem is i can't get a word about Dataprovider ! I'm not a pro in action script coding and the only thing i want is to put each content of each cell of the csv in separate variables ( i.e.: var content1 = Array[1]; ). My csv has the following structure: 8 rows and 3 columns.
Does someone could help me please ?
Thank you