85715

AS3 error #1009

Question:

<br /> When I run the following code I get a error #1009 saying that the var 'list' is null?<br /> 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.<br /> 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); } } }

Answer1:

It's not initialized.

public var list:Array = [];

or

public var list:Array = new Array();

Answer2:

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

Recommend

  • How do i verify form input before displaying record [duplicate]
  • Android : Draw TextEdit(s) or TextView(s) when user enter number of them.[exp: 6 then draw 6 TextVie
  • How to sort list items by their priority in C?
  • Node.js decipher not works for other ciphers' ciphertext
  • five3d local3dtoglobal
  • transparent JDialog becomes opaque when dragging to second screen (ubuntu 14.04 with Cinnamon, java
  • Mouse event in Java
  • How to call functions from sprites in groups?
  • How to change icon image of button on mouse entered/mouse exit?
  • Can I create EventListener in AS3 from one Object and remove it from another Object?
  • How to Optimize mach_msg_trap
  • How many View Controllers should I have in my game?
  • Java : How to tint this PNG programmatically?
  • New Firebase failed: First argument must be a valid firebase URL and the path can't contain “.”
  • JSON encode and decode on PHP
  • Building Qt project for C++11 standard
  • HttpListener.IsSupported is false on XP SP3
  • where do I find the xml.dom python package for the python-2.6.0-8.9.28 and I have a suse/x86_64 vers
  • Can someone please explain to me in the most layman terms how to use EventArgs?
  • Spring boot 2.0.0.M4 required a bean named 'entityManagerFactory' that could not be found
  • Read text file that is not in the main package in a runnable jar
  • Roxygen error “Skipping invalid path”
  • Unable to install Git-core+svn by MacPorts
  • Django simple Captcha “No module named fields” error
  • jQuery ready not fired after rails link_to is clicked
  • how to display data from 1st point on words on y axis for line chart in d3.js
  • Row Count Is Returning the incorrect number using RaptureXML
  • Could not find rake using whenever rails
  • How to rebase a series of branches?
  • Display issues when we change from one jquery mobile page to another in firefox
  • Different response to non-authenticated users and AJAX calls
  • How would I use PHP exceptions to define a redirect?
  • WinForms: two way TextBox problem
  • Arrow is showed instead of the material design version hamburger icon. Why doesn't syncState in
  • Why winpcap requires both .lib and .dll to run?
  • Return words with double consecutive letters
  • Data Validation Drop Down Box Arrow Disappearing
  • Python: how to group similar lists together in a list of lists?
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • Busy indicator not showing up in wpf window [duplicate]