herp-a-derp/Corruption-of-Champions — pull request #50 by Gedan (2013-11-20 20:22:15+00:00)
Title: Re-implemented the base hooking code for the image padding fixup. Much c...

...leaner and neater. Forced a scrollbar update with the padding fix, makes scrollbar appear correctly once padding has been handled.

Quoth the comment block:

The images XY position is relative to its position inside of the containing TextField. Compare the image.Y + image.height to the maximal Y position of text in the TextField /once the image has reflowed the text, possibly adding more height to the text. Handwave the difference in this pixel height as a line count (this could be more accurate by using TextMetrics, but fuck it) and add this many blank lines to the text.
Critical point; once the new lines have been added to the text, force an update of the scrollbar UI element (its actually a seperate UI component that "targets" the TextField, and not actually a part of the TextField itself) to account for the new text height.

Handwavey Bullshit Internals:
TextField.htmlText doesn't continually "parse" content added to it, it's done at the end of a frame when the property has changed.
(TextField has two internal properties to check its current displayed content after parsing, and what other code has told it to have there, the difference is only resolved on EVENT.EXIT_FRAME or EVENT.ENTER_FRAME, I'm not sure which but thats basically the mechanic in play)
TextField never directly updates the UIScrollBar, it's kinda the other way around but not really; the UIScrollBar targets a specific DisplayObject and targets specific properties thereof. It's probably (internally) adding a listener to EVENT.CHANGE which, I believe, will only be fired when the textfields internal text property is updated (ie not htmlText but the comparison with it). Anything that changes the actual content layout of the TextField (and thus the maxScrollV property, which tracks the maximum number of lines displayed via the text field) does not fire the event.

In summary. ADOBE DURR. This kind of stupid, half-implemented interaction between base UI components is systematic.