28Jul

Loading a .CSV File

No comments

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 );
        }
	}
}

Share/Save/Bookmark

Categories: Actionscript 3

Monday, July 28th, 2008 at 9:51 am and is filed under Actionscript 3. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a reply