If you ever using createEmptyMovieClip class or createTextField, or may be attachMovie or any class that you should set / input z-index / depth of that movieClip or textField.
// createEmptyMovieClip method
my_mc.createEmptyMovieClip(instanceName:String, depth:Number) : MovieClip
// createTextField method
my_mc.createTextField(instanceName:String, depth:Number, x:Number, y:Number, width:Number, height:Number) : Void
// attachMovie method
my_mc.attachMovie(idName:String, newName:String, depth:Number [, initObject:Object]) : MovieClip
For just setting up the depth should be no problem if you’re using getNextHighestDepth().
But beware if the depth already reach number higher than 1048575 you will failed when try to do removeMovieClip or removeTextField
Try this:
this.createTextField("my_text", this.getNextHighestDepth(), 100, 10, 10, 10);
my_text.autoSize = true;
my_text.text = "Blah...blah...blah...";
You will see the text “Blah…blah…blah…”
Then when you add removeTextField function (see the script below) you should see the text again.
this.createTextField("my_text", this.getNextHighestDepth(), 100, 10, 10, 10);
my_text.autoSize = true;
my_text.text = "Blah...blah...blah...";
my_text.removeTextField(); //< ---------- remove it
So far is okay let’s say getNextHighestDepth value is equal or lower than 1048575. You still can remove the textField
this.createTextField("my_text", 1048575, 100, 10, 10, 10); //< -- simulate if getNextHighestDepth = 1048575
my_text.autoSize = true;
my_text.text = "Blah...blah...blah...";
my_text.removeTextField();
Then watch what happend if the depth we set higher than 1048575, try 1048576 (just 1 point higher than 1048575)
this.createTextField("my_text", 1048576, 100, 10, 10, 10);
my_text.autoSize = true;
my_text.text = "Blah...blah...blah...";
my_text.removeTextField();
As you see the text will stay, “”Blah…blah…blah…”. This mean is failed when try to remove.
The conculsion for this case is z-index / depth of object still manageable when set lower or equal to 1048575.
Solutions
Because the problem with the z-index. Than the solutions should be fix if we set the z-index to lower.
If the object is already set the z-index higher than 10487575 then you can set it the depth lower before you called remove function. But this only available for MovieClip. Yes you can use swapDepths() for movieclip to reset the z-index lower before you call removeMovieClip() function.
if(mc.getDepth() > 10487575){
mc.swapDepths(123456); // < ---- reset to lower z-index number
}
mc..removeMovieClip();
And for textField problem I’m still not found any solutions because swapDepths() only work for MovieClip not TextField.
The best way is put the TextField in MovieClip so you can reset the z-index using swapDepths(). Or jusy make sure you not set z-index of the TextField higher than 10487575