1 Reply Latest reply on Oct 4, 2006 12:55 PM by Newsgroup_User

    getTextExtent and UI Components

    Level 7
      i've stumbled across a strange bug and am wondering if anyone else has
      seen it. i am creating a text field on the fly and using getTextExtent
      to gauge the height. this all works fine until i call getTextExtent a
      second time (for a second field) at which point the first text field
      disappears. oddly enough it appears to be the presence of UI Components
      in the cast that is causing this.

      try this code in an empty movie to see what i mean...

      /////////////////////////
      var qFormat:TextFormat = new TextFormat();
      with(qFormat){
      font = "_sans";
      size = 14;
      color = 0x000000;
      }
      var qExtent:Object = qFormat.getTextExtent("test text");
      _root.createTextField("qField",_root.getNextHighestDepth(),20,20,qExtent.textFieldWidth,qE xtent.textFieldHeight);
      qField.text = "test text";
      qField.setTextFormat(qFormat);

      qExtent = qFormat.getTextExtent("test text two");
      /////////////////////////

      it should work fine. now add a button or checkbox or whatever component
      to the library (doesn't even have to be on the stage) and the text field
      will not show. if you put a debug stop before the second getTextExtent
      call and run the debugger you can see that the text appears correctly
      then goes away when getTextExtent is called. remove the component from
      the library and it will work fine again.

      has anyone seen this before? can anyone explain the reason the
      components seem to interfere?

      thanks much,
      jb
        • 1. Re: getTextExtent and UI Components
          Level 7
          it turns out the problem is with getNextHighestDepth(), not
          getTextExtent(). i replaced getNextHighestDepth() with a hard coded
          value and it worked fine. i also found this under it's entry in Flash's
          help:

          "Note: If you are using version 2 components, do not use this method. If
          you place a version 2 component either on the Stage or in the Library,
          the getNextHighestDepth() method can sometimes return depth 1048676,
          which is outside the valid range. If you are using version 2 components,
          you should always use the version 2 components DepthManager class."

          still not sure why it displayed fine until the second getTextExtent() call.



          Jeff Blume wrote:
          > i've stumbled across a strange bug and am wondering if anyone else has
          > seen it. i am creating a text field on the fly and using getTextExtent
          > to gauge the height. this all works fine until i call getTextExtent a
          > second time (for a second field) at which point the first text field
          > disappears. oddly enough it appears to be the presence of UI Components
          > in the cast that is causing this.
          >
          > try this code in an empty movie to see what i mean...
          >
          > /////////////////////////
          > var qFormat:TextFormat = new TextFormat();
          > with(qFormat){
          > font = "_sans";
          > size = 14;
          > color = 0x000000;
          > }
          > var qExtent:Object = qFormat.getTextExtent("test text");
          > _root.createTextField("qField",_root.getNextHighestDepth(),20,20,qExtent.textFieldWidth,q Extent.textFieldHeight);
          >
          > qField.text = "test text";
          > qField.setTextFormat(qFormat);
          >
          > qExtent = qFormat.getTextExtent("test text two");
          > /////////////////////////
          >
          > it should work fine. now add a button or checkbox or whatever component
          > to the library (doesn't even have to be on the stage) and the text field
          > will not show. if you put a debug stop before the second getTextExtent
          > call and run the debugger you can see that the text appears correctly
          > then goes away when getTextExtent is called. remove the component from
          > the library and it will work fine again.
          >
          > has anyone seen this before? can anyone explain the reason the
          > components seem to interfere?
          >
          > thanks much,
          > jb