# First Kirupa Post - Problem with changing child index

**URL:** <https://forum.kirupa.com/t/first-kirupa-post-problem-with-changing-child-index/281086>\
**Category:** Uncategorized\
**Created:** [February 4, 2009, 7:26pm UTC](https://forum.kirupa.com/t/first-kirupa-post-problem-with-changing-child-index/281086 "2009-02-04T19:26:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kanji2000](https://avatars.discourse-cdn.com/v4/letter/k/e5b9ba/32.png) [@kanji2000](https://forum.kirupa.com/u/kanji2000)\
**Post date:** [February 4, 2009, 7:26pm UTC](https://forum.kirupa.com/t/first-kirupa-post-problem-with-changing-child-index/281086/1 "2009-02-04T19:26:52Z")

</div>

Hey guys, just signed up and this is my first post. Been running into trouble with the provided code from “Learning Actionscript 3.0: A Beginner’s Guide” by Shupe and Rosser.

When using the example files from the website, I changed the property of setChildIndex. Here is the original code:

> 

[COLOR=“DarkRed”]  
package {  
import flash.display.MovieClip;  
import flash.events.MouseEvent;

```
public class Zsorting extends MovieClip {

	public function Zsorting() {
		this.addEventListener(MouseEvent.MOUSE_OVER, onBringToTop, false, 0, true);
	}
	
	private function onBringToTop(evt:MouseEvent):void {
		var folder:MovieClip = evt.target as MovieClip;
		setChildIndex(folder, numChildren - 1);
	}
}

```

}  
[/COLOR]

\*\*\*Notice setChildIndex(folder, numChildren-1);

I then replaced folder with evt.target and the whole thing WORKS.

Now I tried creating my own flash file and populating it with different movie clips. Here is the code that works:

> 

[COLOR=“DarkRed”]  
package {

```
import flash.display.*;
import flash.events.*;

public class main_swapChildren extends MovieClip {
	
	public function main_swapChildren() {
		
		this.addEventListener(MouseEvent.MOUSE_OVER, onBringToTop, false, 0, true);
		
		function onBringToTop(evt:MouseEvent):void {
			var folder:MovieClip = evt.target as MovieClip;
			var folder02:MovieClip = evt.target as MovieClip;
			var base_folder:MovieClip = evt.target as MovieClip;
			setChildIndex(base_folder, numChildren-1); //--&gt; don't know why but the object base_folder can be
														//--&gt; any of the declared movie clips, ie folder or folder02
		}
	}
}

```

}  
[/COLOR]

Notice setChildIndex(base\_folder, numChildren-1); I can replace base\_folder with any one of the declared movie clips such as folder and folder02AND IT WORKS.

Here’s the problem, using my new flash file, changing setChildIndex(base\_folder with setChildIndex(evt.target [COLOR=“Blue”](which is similar to what I did with the file provided by the website)[/COLOR] produces this error message:

> 

[COLOR=“DarkRed”]  
1118: Implicit coercion of a value with static type Object to a possibly unrelated type flash.display:DisplayObject.

Source: setChildIndex(evt.target, numChildren-1);  
[/COLOR]

Please help me as this is driving me nuts. The files from the website seem to behave differently from the files I’ve created. And I can’t figure out where I went wrong. Any help would be GREATLY appreciated…
