Reputation: 790
When I run the following code I get a error #1009 saying that the var 'list' is null?
Can someone please tell me what's wrong with this AS3 code, I've done lots of searching and read lot of info but no matter how simple the code it's still the same erro #1009 issue.
Thanks,
package
{
import flash.display.Sprite;
import flash.events.MouseEvent;
public class Main extends Sprite
{
public var list:Array;
public function Main() {
stage.addEventListener(MouseEvent.CLICK, add);
}
public function add(e:MouseEvent):void {
list.push("ball");
trace(list);
}
}
}
Upvotes: 0
Views: 1288
Reputation: 10268
You have to instantiate the list, otherwise the list is a reference to nowhere in memory:
public var list:Array = new Array();
or (which is faster in terms of performance than the above):
public var list:Array = [];
Edit: Clarification
Upvotes: 1
Reputation: 7294
It's not initialized.
public var list:Array = [];
or
public var list:Array = new Array();
Upvotes: 0