5 Replies Latest reply on Jan 9, 2014 7:55 AM by sinious

    autoSize not working properly in TextField when using non-zero line spacing

    James22s22 Level 1

      When using non-zero line spacing, the autoSize property is not functioning as expected, causing text fields to scroll that shouldn't.  Also, when using device fonts, the sizes of the TextFields are wrong in the Flash IDE.

       

      I have a TextField whose height is supposed to be dynamic, depending the width of the TextField.  wordWrap is true, the text is left aligned, and the autoSize value is flash.text.TextFieldAutoSize.LEFT.

       

      When the TextField's width is adjusted, the height increases or decreases as expected, but when I scroll the mouse wheel over the TextField, it allows a single line to scroll out of view.  This should not be happening.  The autoSize property should ensure the TextField is large enough to neither require nor allow scrolling.

       

      Has anyone else encountered this issue or know how to fix it?

       

      Update: Been a problem since at least 2006! > http://blog.nthsense.net/?p=46

      http://www.kirupa.com/forum/showthread.php?288955-Disabling-textfield-scrolling   Bug is caused by using a line height ("line spacing" in Flash) larger than zero, for example 1.0pt.  It looks like when I reduce the line spacing of the text field to zero, the issue goes away.  There doesn't seem to be anything wrong with how autoSize is calculating the required height of the text (i.e. it is exactly textHeight + 4 pixel gutter, and drawing the rectangle (2,2,textWidth,textHeight) aligns visually with the text), so it must have to do with how the TextField is deciding whether it needs to scroll or not, and that separate calculation is being thrown off by the non-zero line spacing.  The additional non-zero spacing at the end of the last line could be making the TextField think it needs to scroll, even though it's hight is sufficient at "textHeight + 4".  Apparently the problem manifests when using a non-zero leading value as well.

       

       

       

      In fact, it has to be related to the leading value exactly, since the following code stops the textfield from scrolling.
      //body is TextField

      var tlm:TextLineMetrics = body.getLineMetrics(body.numLines - 1);

      trace(tlm.leading); //traces "1" here.  traces zero when line spacing is zero, and traces larger values with larger line spacing values

      body.autoSize = flash.text.TextFieldAutoSize.NONE; //turn off autosize so the height can be set manually

      body.height += tlm.leading; //increase height of textfield by leading value of last line to cause scrolling to be turned off.

       

      Honestly, this is pretty unacceptable bug.  First of all, scrolling should not be sensitive to trailing line spacing, because autoSize and textHeight do not include it. It need to be consistent, and I think textHeight and autoSize setting height = textHeight + 4 is correct.  Vertical scrolling should use textHeight as it's guage for whether scrolling is necessary, but instead, it's obviously involving the leading values of the last line.  At the very least, vertical scrolling should simply be disabled when autoSize is turned on and wordWrap is true, because the TextField should be big enough to fit all the text.  The workaround of manually adjusting the height is also no good, since turning autoSize back on will immediately change the size back and trigger scrolling again.  I also shouldn't have to set line spacing to zero just to use the autoSize feature, since the scrolling calculations are wrong in this way.

        • 1. Re: autoSize not working properly in TextField when using non-zero line spacing
          sinious Most Valuable Participant

          Not having a good time with TextFields again aye.

           

          Sans the "it should just work" debate, if selecting text isn't useful to your needs you can always set mouseEnabled = false and the scrolling won't be possible.

          • 2. Re: autoSize not working properly in TextField when using non-zero line spacing
            James22s22 Level 1

            No, lol.  Luckly, I replace most of my TextFields on the display list with my subclass TextFieldEx.  I just call a clone method that accepts a TextField and returns a TextFieldEx with identical properties.

             

            I corrected the problem via modifying the subclass to behave differently when autoSize is not NONE and wordWrap is true.  Under those conditions, the maxScrollV and scrollV property values are fixed at 1, and the class listens for its own SCROLL event and sets scrollV to 1 when it occurs.  That allows me to leave everything else alone, including text selection, and use whatever line spacing I want.

             

            The modification seems to work fine so far.

             

            For anyone interested in doing something similar, here is a clone method that will copy a TextField.


            public static function clone( t:TextField ):TextFieldEx

            {

                                          var te:TextFieldEx = create( "", t.width, t.type, t.multiline, t.wordWrap, t.selectable, t.embedFonts, t.defaultTextFormat );

             

                                          te.alpha = t.alpha;

                                          te.alwaysShowSelection = t.alwaysShowSelection;

                                          te.antiAliasType = t.antiAliasType;

                                          te.autoSize = t.autoSize;

                                          te.background = t.background;

                                          te.backgroundColor = t.backgroundColor;

                                          te.blendMode = t.blendMode;

                                          //te.blendShader = t.blendShader;

                                          te.border = t.border;

                                          te.borderColor = t.borderColor;

                                          te.cacheAsBitmap = t.cacheAsBitmap;

                                          te.condenseWhite = t.condenseWhite;

                                          te.displayAsPassword = t.displayAsPassword;

                                          //te.embedFonts = t.embedFonts;

                                          te.filters = t.filters;

                                          te.gridFitType = t.gridFitType;

                                          te.height = t.height;

                                          te.opaqueBackground = t.opaqueBackground;

                                          te.restrict = t.restrict;

                                          //te.selectable = t.selectable;

                                          te.sharpness = t.sharpness;

                                          te.thickness = t.thickness;

                                          te.transform = t.transform;

                                          //te.type = t.type;

                                          te.useRichTextClipboard = t.useRichTextClipboard;

                                          //te.wordWrap = t.wordWrap;

             

                                          //Assign text last

                                          te.htmlText = t.htmlText;

                                          return te;

            }

             

            //And the create method it uses

            public static function create( text:String = "", width:Number = NaN, type:String = null, multiline:Boolean = false, wordWrap:Boolean = false, selectable:Boolean = true, embedFonts:Boolean = false, font_or_textformat:*=null, size:Object=null, color:Object=null, bold:Object=null, italic:Object=null, underline:Object=null, url:String=null, target:String=null, align:String=null, leftMargin:Object=null, rightMargin:Object=null, indent:Object=null, leading:Object=null ):TextFieldEx

            {

                                          var tf:TextFieldEx = new TextFieldEx();

                                          tf.width = isNaN(width) ? 100 : width;

                                          tf.defaultTextFormat = (font_or_textformat is TextFormat) ? (font_or_textformat as TextFormat) : new TextFormat( font_or_textformat as String, size, color, bold, italic, underline, url, target, align, leftMargin, rightMargin, indent, leading );

                                          tf.embedFonts = embedFonts;

                                          tf.multiline = multiline;

                                          tf.wordWrap = wordWrap;

                                          tf.selectable = selectable;

                                          tf.type = type;

                                          tf.text = text; //setting text last ensures the text line metrics returns correct values

             

                                          //Initialize the TextField's size to fit the text.

                                          if (!multiline)

                                          {

                                                    //When in single-line mode and no specific width is given,

                                                    //expand width to entire line.

                                                    if (isNaN(width))

                                                              tf.width = tf.textWidth + 4; //match width of text

                                          }

             

             

                                          //Height is always automatically adjusted to fit the text by default.

                                          //It's better than the arbitrary 100px default height.

                                          var minimum_height = tf.getLineMetrics( 0 ).height;

                                          var h:Number = tf.textHeight;

                                          tf.height = (h < minimum_height) ? (minimum_height + 4) : (h + 4); //match height of text, ensuring height is at least enough to display one line, even if there is no text

             

                                          return tf;

            }


            • 3. Re: autoSize not working properly in TextField when using non-zero line spacing
              sinious Most Valuable Participant

              You might as well just github it and start rewriting your own entire TextField class . Toss in some built in easy-mode effects, transitions, etc. I want a built in LED display mode and maybe a classic netscape blink and IE marquee!

               

              Silly aside, you are posting bug reports for these right? You should post the bugbase links so we can vote it up. I think this may fall safely inside the realm of "Flash Player" to use bugbase.

              • 4. Re: autoSize not working properly in TextField when using non-zero line spacing
                James22s22 Level 1

                Yes, I did post the bug.  At first I was having trouble accessing the site, it kept saying there was some kind of redirect loop, and I read online that clearing the cookies and cache would help.  It fixed the problem.  I had the same problem with a banking site once.  I suspect the webmaster once set a permanent redirect that was no longer valid... that stuff gets cached forever in browser, which is why I never use permanent redirects.

                 

                The bug is here: https://bugbase.adobe.com/index.cfm?event=bug&id=3690516

                 

                I will eventually post my entire FLOS (Flash Operating System) framework; it includes tons of stuff, even a JSON serializer that is fully type-safe and supports everything from circular references, object references in dictionaries, byte arrays, signed/unsigned 64-bit integers, GUIDs, full-precision (datetime2(7)) database dates, and more.  Ripple shaders, focus managers and focus loops, key polling, dynamic dashed lines, reflection utilities, complex mouse events, support for WebSockets, chained-function based pseudo threading, centralized timers, widgets, string utilities, mp3 pitch shifters, static stage references, and more.

                • 5. Re: autoSize not working properly in TextField when using non-zero line spacing
                  sinious Most Valuable Participant

                  Sounds like a big batch of useful framework extensions. I wouldn't go as far as to call it "OS" unless you're writing a new SWF runtime.

                   

                  I voted up the bug. If you open bugs for the metrics I'll be happy to vote there as well. I have designers who're continuously ticked off by typography not being identical to their mockups like everyone else..

                  1 person found this helpful