I'm having trouble removing drag and drop MovieClips when they are not placed in the right spot. In the code below I have it so if the drag and drop movieclip is not placed on the target, it removes itself. I tried this with parent.removeChild(this); and this.parent.removeChild(this); and both give me this error "TypeError: Error #1009: Cannot access a property or method of a null object reference.
at DragDropObject/onUp()"
PHP Code:
private function onUp(e:MouseEvent):void {
this.stopDrag();
this.removeEventListener(MouseEvent.MOUSE_OUT, onUp);
for(var n:int=0; n<_target.length; n++){
//only continue if a target has been set
//if (_target != null){
trace("hey " + this.hitTestObject(_target[n]));
if ((this.hitTestObject(_target[n]) == true) && (e.type != MouseEvent.MOUSE_OUT)) {
trace("hey again");
this.x = _target[n].x;
this.y = _target[n].y;
this.dispatchEvent(new Event (DragDropObject.PLACED));
break;
} else {
if (_snapBack == true) {
parent.removeChild(this);
//this.parent.removeChild(this);
//this.x = startX;
//this.y = startY;
this.dispatchEvent(new Event (DragDropObject.SNAPPED));
}
//}
}
}
}
}