Keep On Top

I’ve checked through a bunch of topics attempting to keep a Movieclip on highest index level, but none of them seem to work perfectly for me. Here is the code I am using to keep a Movieclip above two different backgrounds:

_root.setChildIndex(this,_root.numChildren-1);

I also tried this, thinking it might be faster:


for (var i:int=0; i<_root.bgArray.length; i++) {
	for (var j:int=0; j<_root.bgArray*.length; j++) {
		var mc:Object=_root.bgArray*[j];
		if (_root.getChildIndex(mc)>_root.getChildIndex(this)) {
			_root.setChildIndex(this,_root.getChildIndex(mc));
		}
	}
}

And here is the code to keep the front background above the back background:


for (var i:int=0; i<_root.bgArray[1].length; i++) {
	var mc:Object=_root.bgArray[1]*;
	if (_root.getChildIndex(mc)>_root.getChildIndex(this)) {
		_root.setChildIndex(this,_root.getChildIndex(mc));
	}
}

The plan is to keep the back background (located in _root.bgArray[1]) in the very back, with the front background (located in _root.bgArray[0]) one level higher, and the Movieclip on top. The thing is, the backgrounds scroll from right to left, simulating a moving effect. When the entire background passes the length of the stage, it creates another one to make it look like it is continuing, and then deletes itself when it is no longer visible. The effect is a pseudo never-ending background.

This all seems to work perfectly, but every few seconds or so, the Movieclip disappears to the back, or at least behind the front background, for a frame or so and then returns to the top. How do I fix this? Thank you in advance :smiley: