"The supplied DisplayObject must be a child of the caller"

Hey everyone. I got an annoying problem that I can’t figure out.

Code:

package {

import flash.display.MovieClip;
import flash.events.*;

public class PhotoBrowser extends MovieClip {

var thumbnails:Array = new Array();

public function PhotoBrowser() {
	continue_btn.addEventListener(MouseEvent.CLICK, playMovie);
	forward.addEventListener(MouseEvent.CLICK, gotoFrame40);
	backward.addEventListener(MouseEvent.CLICK, gotoFrame20);
	search_btn.addEventListener(MouseEvent.CLICK, search);
}


function playMovie(e:MouseEvent) {
	play();
}

function gotoFrame40(e:MouseEvent):void {
	gotoAndStop(40);
}

function gotoFrame20(e:MouseEvent) {
	gotoAndStop(20);
	for (var p:int = 0; p < thumbnails.length; p++) {
		thumbnails[p].visible = true;
	}
}

function gotoLargeThumb(e:MouseEvent):void {
	gotoAndStop(40);
	for (var k:int = 0; k < thumbnails.length; k++) {
		thumbnails[k].visible = false;
	}
}

function search(e:MouseEvent) {
	var query:int = int(search_txt.text);
	trace(query);
	
	for (var n:int = 0; n < thumbnails.length; n++) {
		this.removeChild(thumbnails[n]);
		thumbnails[n].removeEventListener(MouseEvent.CLICK, gotoLargeThumb);
	}
	
	var xpos:int = 105;		
	var ypos:int = 265;
	for (var i:int = 0; i < query; i++) {
		var thumb:Thumbnail = new Thumbnail();
		thumb.scaleX = 0.5;
		thumb.scaleY = 0.5;
		thumb.x = xpos;
		thumb.y = ypos;
		xpos += thumb.width + 10;
		thumbnails* = thumb;
		this.addChild(thumbnails*);		
		thumbnails*.addEventListener(MouseEvent.CLICK, gotoLargeThumb);
	}			
}

}

}

Output:

1
2
3
4
3
2
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at PhotoBrowser/search()