I'm trying to implement CSVLib in an Air application and am getting an error that seems wholly illogical to me.
"1120: Access of undefined property csv." and "1120: Access of undefined property completeHandler."
The only thing I can think is it's not importing the csv class properly, or the class itself is broken somehow? I know my import path is correct because I typed it out directly based on automatic hinting. The code below is copied directly from the how-to wiki on the csv lib site.
Or is there something special you need to do to get external actionscript classes to work in flashbuilder?
<fx:Script>
<![CDATA[
import com.shortybmc.*;
import com.shortybmc.data.parser.CSV;
var csv:CSV = new CSV();
csv.addEventListener (Event.COMPLETE, completeHandler);
csv.load (new URLRequest('example-2.csv'));
function completeHandler (event: Event)
{
trace ( csv.data.join('\r') );
// do something ...
}
]]>
</fx:Script>
In this case, the problem is somewhere else. The fx:Script
tag is within a MXML file, which represents a class definition.
Your error happens, because you have code within the class definition (i.e. outside of a method). You can write this instead for example:
<fx:Script>
<![CDATA[
import com.shortybmc.*;
import com.shortybmc.data.parser.CSV;
private var csv:CSV;
private function init ():void
{
csv = new CSV();
csv.addEventListener (Event.COMPLETE, completeHandler);
csv.load (new URLRequest('example-2.csv'));
}
private function completeHandler (event: Event):void
{
trace ( csv.data.join('\r') );
// do something ...
}
]]>
</fx:Script>
Then you need to make sure that the init
method is actually called; you can do this in the complete handler of your MXML object.