Tutorial by Examples

Sometimes developers write some code that desires access to stage, or Flash stage, to add listeners. It can work for the first time, then all of a sudden fail to work and produce the error 1009. The code in question can even be on the timeline, as it's the first initiative to add code there, and man...
function listener(e:Event):void { var m:MovieClip=e.target as MovieClip; m.x++; } If such a listener is attached to an object that's not a MovieClip descendant (for example, a Sprite), the typecast will fail, and any subsequent operations with its result will throw the 1009 error.
var a:Object; trace(a); // null trace(a.b); // Error 1009 Here, an object reference is declared, but is never assigned a value, be it with new or assignment of a non-null value. Requesting its properties or method results in a 1009 error.
x=anObject.aProperty.anotherProperty.getSomething().data; Here, any object before the dot can end up being null, and using methods that return complex objects only increases the complication to debug the null error. Worst case if the method is prone to extraneous failures, say retrieving data ove...
s=this.getChildByName("garbage"); if (s.parent==this) {...} getChildByName() is one of the many functions that can return null if an error occurred when processing its input. Therefore, if you are receiving an object from any function that can possibly return null, check for null first...
addEventListener(Event.ENTER_FRAME,moveChild); function moveChild(e:Event):void { childMC.x++; if (childMC.x>1000) { gotoAndStop(2); } } This example will move the childMC (added to Main at design time) but will instantly throw a 1009 as soon as gotoAndStop() is invok...
Sometimes gotoAndStop() is called in the middle of the code that refers some frame-based properties. But, right after the frame is changed all links to properties that existed on the current frame are invalidated, so any processing that involves them should be immediately terminated. There are two ...

Page 1 of 1