Action Script & Tutorials 21 Dec 2005 04:31 pm

Watch out! z-index limit until 1048575

(Visited 2181 times)

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.

Actionscript:
  1. // createEmptyMovieClip method
  2. my_mc.createEmptyMovieClip(instanceName:String, depth:Number) : MovieClip
  3. // createTextField method
  4. my_mc.createTextField(instanceName:String, depth:Number, x:Number, y:Number, width:Number, height:Number) : Void
  5. // attachMovie method
  6. 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:

Actionscript:
  1. this.createTextField("my_text", this.getNextHighestDepth(), 100, 10, 10, 10);
  2. my_text.autoSize = true;
  3. 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.

Actionscript:
  1. this.createTextField("my_text", this.getNextHighestDepth(), 100, 10, 10, 10);
  2. my_text.autoSize = true;
  3. my_text.text = "Blah...blah...blah...";
  4. 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

Actionscript:
  1. this.createTextField("my_text", 1048575, 100, 10, 10, 10); //<-- simulate if getNextHighestDepth = 1048575
  2. my_text.autoSize = true;
  3. my_text.text = "Blah...blah...blah...";
  4. my_text.removeTextField();

Then watch what happend if the depth we set higher than 1048575, try 1048576 (just 1 point higher than 1048575)

Actionscript:
  1. this.createTextField("my_text", 1048576, 100, 10, 10, 10);
  2. my_text.autoSize = true;
  3. my_text.text = "Blah...blah...blah...";
  4. 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.

Actionscript:
  1. if(mc.getDepth()> 10487575){
  2.          mc.swapDepths(123456)// <---- reset to lower z-index number
  3. }
  4. 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 :)

2 Responses to “Watch out! z-index limit until 1048575”

  1. on 31 Aug 2006 at 3:33 pm 1.franklin said …

    Perfect!!

    I was stressing. Now im relaxed again.

    thankyou();

  2. on 10 Mar 2007 at 6:25 pm 2.DEC said …

    Hello,

    May be a solution for TextField could be found from this "old" tutorial" from SENOCULAR :
    http://www.senocular.com/flash/tutorials/depths/

    Read the first page, you'll be astonished... swapDepths may be available for TextFields and buttons...

    Thank-you for your site where I often find inspiration.
    Bye
    Philippe

    PS : and thank's to Trevor (Senocular) of course...

Trackback This Post | Subscribe to the comments through RSS Feed

Leave a Reply

You must be logged in to post a comment.