removeMovieClip causes script malfunction

1 post

Flag Post
class paraspritePZG extends MovieClip {
	
	var unicorn:MovieClip;
	var health: Number = 1;
	var invincibility: Number;
	var dir: Number;
	var dy: Number = 0;
	var dx: Number = 0;
	var oldX: Number;
	var oldY: Number;
	var friction: Number = 1.2;
	var counter: Number = 0;
	var variant: Number;
	var currentSprite: MovieClip;
	var order: Number;
	
	function onEnterFrame() {
		if( unicorn.unpaused) {
			if( health > 0) {
				if(unicorn.moving) {
					trace( this);
					this.removeMovieClip();
				}//end if root frame
				dx += Math.random() * 4 - 2;
				dy += Math.random() * 4 - 2;
				//hurt twiliy
				if(hitTest(unicorn)) {
					unicorn.hurt( 0.5 );
					trace (unicorn.health);
				}//end hittest
				//movement
				_x += dx;
				_y += dy;
				dx /= friction;
				dy /= friction;
				//bounds
				if( _x > Stage.width) {
					_x = Stage.width;
				}//end if
				if( _x < 0) {
					_x = 0;
				}//end if
				if( _y > Stage.height) {
					_y = Stage.height;
				}//end if
				if( _y < 0) {
					_y = 0;
				}//end if
				
				//get hurt
				//melee
				if(hitTest(unicorn.melee)) {
					if (unicorn.melee.power > 0){
						hurt( unicorn.attack );
					}//end if power
				}//end if hitest
				//laser
				for( var i: Number = 0; i <= unicorn.i; i++) {
					if( hitTest(eval ("laser" + i))) {
					   eval ("laser" + i).removeMovieClip();
					   hurt( unicorn.power );
					}//end if
				}//end for
				//invicibility
				if( invincibility > 0) {
					invincibility--;
				}//end if invincible
				//animation
				counter++;
				switch( variant) {
					case 1:
					if( counter % 6 < 3) {
						gotoAndStop( 1 );
					} else {
						gotoAndStop( 2 );
					}
					break;
					case 2:
					if( counter % 6 < 3) {
						gotoAndStop( 3 );
					} else {
						gotoAndStop( 4 );
					}
					break;
					case 3:
					if( counter % 6 < 3) {
						gotoAndStop( 5 );
					} else {
						gotoAndStop( 6 );
					}
					break;
				} //end switch
				//spawning
				switch( variant ) {
					case 1:
					if( counter % 300 == 233) {
						spawn();
					}
					break;
					case 2:
					if( counter % 300 == 245) {
						spawn();
					}
					break;
					case 1:
					if( counter % 300 == 257) {
						spawn();
					}
					break;
				}
			} else {
				gotoAndStop( 7 );
			}//end if health
		}//end if unpaused
	}//end enter frame
	
	public function hurt( damage) {
		trace( invincibility);
		if( invincibility <= 0 && health > 0) {
			trace( "ouch")
			health -= damage;
			invincibility = 5;
		}//end if
	}//end hurt
	
	public function spawn() {
		_root.attachMovie( "parasprite", "parasprite" + unicorn.i, unicorn.i);
		currentSprite = eval ( "parasprite" + unicorn.i);
		currentSprite._x = _x;
		currentSprite._y = _y;
		currentSprite.unicorn = unicorn;
		currentSprite.variant = Math.ceil(Math.random() * 3);
		currentSprite.order = unicorn.i;
		unicorn.i++;
	}//end spawn
	
}//end class

For some reason this class makes the script halt when I remove it, but none of my other classes do. Why, and how do I fix it?