Disappearing AS generated movieclips and textfields

This issue seems rather bizarre to me but I suspect that what I am missing is something obvious. The visual output that I would expect from the code below is a diagonal string of ten number signs each followed by its own value of i. However, instead I find a “#9” in the bottom right hand corner.

The output box displays:


#0
outer0
#1
outer1
etc...


    var i = 0;
    var myObj:Array = new Array();
    while(i<10){
        myObj* = "outer"+i;
        this.createEmptyMovieClip("outer"+i, 0);
        this[myObj*]._x = i*50;
        this[myObj*]._y = i*50;
        this[myObj*].createTextField("inner", 1, 0, 0, 100, 100);
        this[myObj*].inner.text = "#"+i;
        trace(this[myObj*].inner.text);
        trace(myObj*);
        i++;
    }

Shouldn’t the movieclip generated by createEmptyMovieClip() persist through each iteration of the while loop instead of disappearing every time i changes? I can see that happening when using the debugger. What should I do to cause each of the movie clips generated to remain on the screen?

Thanks,
M. Vatki

You’re creating all of them at the same depth (0) which isn’t possible. You’ll have to make a new depth for each one. Something like this:

var i = 0;
var myObj:Array = new Array();
while (i < 10) {
	myObj* = "outer" + i;
	this.createEmptyMovieClip("outer" + i, i);
	this[myObj*]._x = i * 50;
	this[myObj*]._y = i * 50;
	this[myObj*].createTextField("inner", 1, 0, 0, 100, 100);
	this[myObj*].inner.text = "#" + i;
	trace(this[myObj*].inner.text);
	trace(myObj*);
	i++;
}

Thanks for the quick response. I didn’t know that depth differences were mandatory :). It makes sense now though.