Skip to content


Loading a .CSV File

My next project involves loading of a .csv file and then having the ability to execute methods to the data. I have searched around and found this sweet project:

http://www.elegantfloraldesigns.us/blogstuff/ProgressBarCsvConversionExample/
ProgressBarCsvConversionExample.html

I should also mention that since my next project will be based more on data, that Flex would be a better application for this… but the following is the Actionscript 3:

package
{
	import flash.display.Sprite;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.events.Event;

	import flash.events.IEventDispatcher;

	public class LoadCSV extends Sprite
	{
		public function LoadCSV():void {

			var loader:URLLoader = new URLLoader();
            configureListeners(loader);

            var request:URLRequest = new URLRequest("http://www.???.com/path/to/csv/file.csv");

            try {
                loader.load(request);
            } catch (error:Error) {
                trace ("Unable to load requested document.");
            }
		}

		private function configureListeners(dispatcher:IEventDispatcher):void {
            dispatcher.addEventListener(Event.COMPLETE, completeHandler);
        }

		private function completeHandler(event:Event)
		{
			trace ( event.target.data );
        }
	}
}

Posted in Actionscript 3.


One Response

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Kalavati Singh says

    Hi,

    According to my current requirement I want to know is there simple Flex compatible parser for use in parsing CSV (comma separated value) format files. This may already be available in Flex Builder. If not what is the best way to parse these files.

    Regards

    Kalavati Singh

    kalavati_singh@yahoo.co.in



Some HTML is OK

or, reply to this post via trackback.