ActionScript 3 Understanding the "Error 1009: Cannot access a property or method of a null object reference" Invalid typecast


Example

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.