Tuesday, March 1, 2011

Flash Error #1009: Cannot access a property or method of a null

This Flash action script error 1009 "cannot access a property or method of a null" or "null has no properties" usually happens when the object you are trying to access is not on stage or has not been instantiated, yet you are trying to access a method or a property on that object.

Solution:

If you are unsure check if the object is exists before calling methods or accessing its properties.  Ex:

if( object != null )
    object.doSomethingFun();

or if you are unsure if the object exists or not on stage do an if check!
if( object != null )
    stage.removeChild(object);

I hope that helps.  If you have questions, feel free to leave comments.

Related Links:
list of errors


No comments:

Post a Comment