7 Replies Latest reply on Jan 15, 2008 11:31 AM by Paul-Cripps

    ComboBox - text field / metrics problem

    Paul-Cripps
      When I create text on the fly it works fine, until I import comboBox controls:
      //import mx.controls.ComboBox;

      This is true ONLY when using textMetrics to get the textFieldHeight.

      Has anyone else seen this, is there a work arounf or have I missed something?


      ------------------ CODE EXAMPLE - comment and change to test --------------------------------------

        • 1. Re: ComboBox - text field / metrics problem
          robdillon Most Valuable Participant
          try setting a variable to the value of metrics.textFieldHeight and then use that variable as a parameter in the createTextField() function.
          • 2. Re: ComboBox - text field / metrics problem
            Paul-Cripps Level 1
            Even without using the text metrics, just having the metrics object:

            var metrics:Object = my_fmt.getTextExtent(theString, 210);

            And the import component code it doesnt work?
            • 3. Re: ComboBox - text field / metrics problem
              robdillon Most Valuable Participant
              You need to place a copy of the component in your movie's Library.
              • 4. Re: ComboBox - text field / metrics problem
                Paul-Cripps Level 1
                Ok, still no joy!

                I tried adding a component to the stage itself and just in the library. BOTH attempts break and the text does not render.

                Once the combo is removed from the library it works again?!

                Can you confirm you've ried the same code and it works?
                • 5. Re: ComboBox - text field / metrics problem
                  rlc5611 Level 1
                  I believe that the source of the problem is the use of _root.getNextHighestDepth(). When you use Flash components, they automatically create two "reserved" clips at depths 1048574 and 1048575. When you simply use the "import" with no Combobox present in the library, it creates a clip named "reserved" at a depth of 1048575. In either case, your movieclip created with _root.getNextHighestDepth() will then go to a higher depth than that which is in the special reserved (forget the actual name) of depths and chaos occurs. Flash won't fail but things do not behave as expected.

                  So you need some method to ensure that depths (in the _root) you create remain below that ceiling. One simple way is to create a container clip of known depth or even have it on the stage so it gets a negative depth. You can then use getNextHighestDepth() within that clip with no problems because the parent clip will still be in the normal range of depths. You could also try swapDepths() method to "move" those offending clips to lower levels. I have done this with no resulting problems that were deal-breakers although I think I remember that I had to avoid negative depths. This is a well known problem with Flash components and one that has apparently never been resolved.

                  Even if you place the "import.mx.controls" or attach an actual component inside a movie clip, those special reserved clips are still always created only in the _root and always at the depths previously mentioned. They will not appear in the movie clip's timeline. So a really effective way to avoid this ever being a problem is simply to make your movie a movie clip and do all your work within that clip and use "this" instead of "_root".

                  getNextHighestDepth() only ever "fails" in the _root. It does not "fail" within clips. There are ways around the problem. Easiest way is never use Flash components. Second easiest way is to work only inside of clips with known depths. Third easiest way is make your own customized depth manager function and avoid getNextHighestDepth(). More risky is swapDepths() with the "reserved" clips. Personally I would avoid that last one based on experience because it can affect the behavior of the component (they still work but may not display as expected).

                  BTW, using the below script you will see that your movie clip where you are trying to put the text never gets created which is why it cannot display anything.

                  For debugging, I've always found this very useful to see what Flash is doing:

                  • 6. Re: ComboBox - text field / metrics problem
                    rlc5611 Level 1
                    And for what it's worth, your text metrics are not failing. I tried both with and without the "import" the following code and got the same result:

                    • 7. Re: ComboBox - text field / metrics problem
                      Paul-Cripps Level 1
                      rlc5611 - thats great to know, thanks for the info.

                      The clients not too happy standard components anyway so I dare say its going to change! and I'll be creating our own, but its good to know how components work.

                      Many thanks, Paul.