
It’s been a while since I’ve posted anything on here. Things have been soo busy recently, I’ve had some really exciting projects to work on including more portfolio websites and online ad campaign and my handy work is even going to be featured on a TV campaign coming up.
There has been a bug in flash that has always niggled me, and I’ve always wanted to try and find a solution but for one reason or another never had a chance to. This bug occurs when you dynamically insert text in to a TextField in Flash which is allowed to autoSize and then selected all the text by dragging. In most cases, as you drag down the text will scroll up 1 line and you will loose the top line. This is a really ugly bug.
After reading Tomek’s blog post on the same bug and his fix , I’ve managed to discover what the problem is and the slightly modified (improved… cough, cough) on Tomek’s solution.
Tomek’s solution worked perfectly, which was to insert the text, store the height, set the autoSize property to NONE and then manually increase the height of the TextField. This means that the text fits within the resizes TextField fully and does not need to scroll.
The thing I didn’t like is that I was just adding 10 pixels to the height. What if I was using a large font size and that solution didn’t work? After some experimenting I found that the value you need to increase the height of the TextField by is the leading. So if your leading is 0 the bug will not appear, if you leading is something crazy like 24, then you will need to add 24 pixels to the height of your dynamic TextField. It seems that when Flash resizes the TextField as you flow the copy in, it doesn’t take in to account the leading, or at least ignores it on the last line.
My Solution is this:
- Set the autoSize property to LEFT (or similar)
- Insert the text
- Store the height
- Set the autoSize property to NONE
- Increase the height by adding the leading value of the TextField’s TextFormat object.
text2.autoSize = TextFieldAutoSize.LEFT; text2.text = lipsum; var h : Number = text2.height; text2.autoSize = TextFieldAutoSize.NONE; text2.height = h + text2.getTextFormat().leading;