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

**URL:** <https://forum.kirupa.com/t/the-supplied-displayobject-must-be-a-child-of-the-caller/324451>\
**Category:** flash\
**Created:** [August 22, 2011, 6:12am UTC](https://forum.kirupa.com/t/the-supplied-displayobject-must-be-a-child-of-the-caller/324451 "2011-08-22T06:12:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dave\_incubus](https://avatars.discourse-cdn.com/v4/letter/d/74df32/32.png) [@dave\_incubus](https://forum.kirupa.com/u/dave_incubus)\
**Post date:** [August 22, 2011, 6:12am UTC](https://forum.kirupa.com/t/the-supplied-displayobject-must-be-a-child-of-the-caller/324451/1 "2011-08-22T06:12:38Z")

</div>

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 &lt; thumbnails.length; p++) {
		thumbnails[p].visible = true;
	}
}

function gotoLargeThumb(e:MouseEvent):void {
	gotoAndStop(40);
	for (var k:int = 0; k &lt; 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 &lt; 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 &lt; 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()
