Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Loading a CSV file and accessing the variables

Participant ,
May 06, 2009 May 06, 2009

Hi guys,

I'm new to AS3 and dealt with AS2 before (just getting the grasp when the change it).

Is it possible in AS3 to load an excel .csv file into Flash using the URLLoader (or ???) and the data as variables?

I can get the .csv to load and trace the values (cell1,cell2,cell3....) but I'm not sure how to collect the data and place it into variables.

Can I just create an array and access it like so.... myArray[0], myArray[1]? If so, I'm not sure why it's not working.

I must be on the completely wrong path. Here's what I have so far....

var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, dataLoaded);

var request:URLRequest = new URLRequest("population.csv");
loader.load(request);
//...
function dataLoaded(evt:Event):void {
    var myData:Array = new Array(loader.data);
    trace(myData);

}

Thanks for any help,

Sky

TOPICS
ActionScript
4.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 06, 2009 May 06, 2009

just load your csv file and use the flash string methods to allocate those values to an array:

var myDate:Array = loader.data.split(",");

Translate
Community Expert ,
May 06, 2009 May 06, 2009

just load your csv file and use the flash string methods to allocate those values to an array:

var myDate:Array = loader.data.split(",");

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 06, 2009 May 06, 2009
LATEST

Thanks again Kglad, your one of the most helpful and reliable people out there.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines