how to change text vertical offset in textfield as3 - actionscript-3

Hello.
Is there any way to discover how big is vertical offset in text field(red line, place beetween begining of text field and start of text). Can I also change it ?
Thank you for advice

There is no way to measure this distance. Maybe TextLineMetrix can help you little. Check this document:
textLineMetrics reference
Also you can use textHeight property of text field.

you can trace a comparison between the property textHeight and textField.height that may tell you the difference.
if you want to adjust it manually a work around may be in order such as creating a Sprite that holds the graphics of your box, or border like you have displayed, then imposing a textField on that which you can place by its coordinates.

Related

autosizing movieclips to match text size (AS3)

I'm looking to add a specialized border around some dynamic text.
A special type of border that filters just can not produce
So I need this border to match the length of the dynamic text.
Unfortunately this code is not working
thistext.autoSize = TextFieldAutoSize.LEFT;
border.width = thistext.width;
What happens is, the border width is set to the initial starting width of the text and is not changed as the width of the text changes
Any ideas on how I can make this work?
You should rather listen only to text changes : flash.events.Event.CHANGE, instead of checking every frame.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/TextField.html#event:change
Besides, you may use textWidth attribute to get actual text width, no matter the value of autosize attribute (Width must be set to the maximum width). I'm not a huge fan of auto size feature which hides the maximum width, although it exists internally ( equal to the width attribute of the textfield, BEFORE setting autosize..). I'd rather have a less "magical" but more clear behavior, but it's debatable, especially if your text has to interact with the mouse (click,hover..), then you can take advantage of the bounds being automatically updated
I actually caught my mistake.
I need to add the code into an event listener that checks every frame AFTER the dynamic change so this code works
border.width = thistext.width;

Setting QTextDocument painter's rectangle (where to paint)

I am painting on a window simple html using QTextDocument::drawContents(painter)
I want to do the drawing inside some margins in the window but I don't see a direct way to specify the target rectangle of the painting (in the painter/window).
I guess a few ways to do it:
Using the QTextDocuments::setMargin (although this does not allow different values for left/top.
Placing the html into an styled <div>
Applying a translation transform to the painter.
But all this seems a bit too much for what I want to do and I guess if I a missing something straight (as you do with QPainter::drawText where you tell the target rectangle)
Set the textWidth property to the width of the area where the text is supposed to fit. The clipping rectangle you pass to drawContents will cut the text off vertically if there's too much of it to fit; you can't do much about that of course.
So, this would be the missing function you're after:
void drawContents(QPainter * p, QTextDocument & doc, const QRectF & rect) {
p->save();
p->translate(rect.topLeft());
doc.setTextWidth(rect.width());
doc.drawContents(p, rect);
p->restore();
}
Yes, you do need to jump through a few hoops, that's why it needs to be factored out. It's perhaps lamentable that a similar overload of drawContents doesn't exist.

TextField padding

I'm working on this nametag designer project, and because the elements are later added to pdf, i need to know the EXACT placement on the tag.
TextField's are giving me some problems, cause the textfield "padding" changes when you change the fontsize.
I either need to remove the "padding" or get the x,y position of the text inside the TextField.
Leading test:
Any ideas on this! Thanks!
I'm not sure what "padding" you need, but you can get all offsets with this methods: getCharBoundaries(), getLineMetrics().

AS3 Dynamic text box over button

In AS3 I have a button on the stage and above it I create a textbox box dynamically with code.
My problem is that the area that is under the text (i.e. that part of the button) is no longer clickable.
I have set:
tBox.selectable = false;
but that doesn't solve it.
Any ideas
Season greetings,
Luben
Use InteractiveObject.mouseEnabled:
textField.mouseEnabled=false;
If you set component.visible to false it does not interact with the user.
So, if you set tBox.visible = false then it will be invisible and the button will become clickable. Just a thought, but overlapping components is really bad UI design. If you have space on your stage, you should consider keeping them separate
The problem is that text field (despite it's transparent) is lying over button. To make click on button possible you have to be sure that button is in front of text. Take a look at AddChildAt method of DisplayObject. Objects with greater position index are lying over objects with lower position index. So all you need is to make sure that button has greater index:
container.addChildAt(button, 1)
...
container.addChildAt(text, 0)
P.S.: you may embed button dirrectly into text field using html <a href="javascript:..."><img src="link_to_image"><a/> or something like that.

AS3 AutoSize Textfield

in AS3, I'm making this dynamic textfield that is populated from an XML file based on where the user clicks.
The dynamic textfield has a custom scrollbar to it. My problem is that if the text inserted into the textfield is less than the previously displayed text, you can still scroll the dynamic textfield as far as the previous one.
Is there a way to reset the textfield autoSize?
Many thanks,
If you are talking about Flash ( I have very little experience in Flex ) then the textField.autosize property would probably get you in the right direction.
I think this link will tell you exactly what to do.
Are you using any of the standard flex controls? Or, is this flash?
You can set the width of the field to the string length + some space (by binding the width to the string's length/event handling etc). This may be of interest. Of course,
Try this, wrap the xml elements text in
<text><![CDATA[<span class="someClass">Some Text Here</span>]]></text>
If the prior wasn't wrapped in CDATA, flash would have taken the <span class="someClass"> and attempted to drop it down a line and indent it as you would with XML hierarchy; CDATA tells flash to ignore those characters and literally treat them as a string. The result of not using this process is that there are many odd spacings in your textfield.
Also be sure that your TextField is set to Multiline and wordwrap, as well as autoSize such as TextFieldAutoSize.LEFT;