01-07-2011 08:35 AM - edited 01-07-2011 08:35 AM
Has anyone got the label to center justify with wrap around?
Sample:
var textmsg :Label = new Label(); textmsg.setSize( 300, 200 ); textmsg.textField.wordWrap = true; textmsg.textField.multiline = true; textmsg.text = 'hello world\nthis is a long text that I want centered and wrap around to look very nice to the user.'; textmsg.autoSize = TextFieldAutoSize.CENTER; addChild( textmsg );
01-07-2011 08:56 AM
hey john,
im not sure exactly which effect you are going for but by applying a textformat to the label and setting the align to center should center all the text in a label such as follows:
var textmsg :Label = new Label();
textmsg.setSize( 300, 200 );
textmsg.textField.wordWrap = true;
textmsg.textField.multiline = true;
var myFormat:TextFormat = new TextFormat();
myFormat.align = TextFormatAlign.CENTER;
textmsg.text = 'hello world\nthis is a long text that I want centered and wrap around to look very nice to the user.';
textmsg.format = myFormat;
textmsg.autoSize = TextFieldAutoSize.CENTER;
addChild( textmsg );
Hope thats what you are looking for. good luck!
01-07-2011 09:12 AM
Works great on just text, but if the textField is HTML, it seems to ignore it (using .htmlText).
01-07-2011 09:14 AM
if you are using htmlText chances are you are going to have to use html tags within your string to format it. the only i can think of doing it from the outside like via code is by applying a stylesheet to your label object. do you have a sample of the htmlText you are using?
01-07-2011 09:23 AM
Nothing special:
<u>Compass</u>\n<b>Company Name</b>\nCopyright
01-07-2011 09:34 AM
hey john,
just tried it and it works fine on my end. here is the code im using to test it out. maybe there is something different im doing. also note i applied a red background to show that it is infact centered:
package
{
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
import qnx.ui.text.Label;
[SWF(width="1024", height="600", backgroundColor="#CCCCCC", frameRate="30")]
public class LabelTest extends Sprite
{
public function LabelTest()
{
super();
// support autoOrients
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
var textmsg :Label = new Label();
textmsg.setSize( 300, 200 );
textmsg.textField.wordWrap = true;
textmsg.textField.multiline = true;
var myFormat:TextFormat = new TextFormat();
myFormat.align = TextFormatAlign.CENTER;
textmsg.htmlText = '<u>Compass</u>\n<b>Company Name</b>\nCopyright';
textmsg.format = myFormat;
textmsg.autoSize = TextFieldAutoSize.CENTER;
textmsg.graphics.beginFill(0xFF0000);
textmsg.graphics.drawRect(0,0,textmsg.width,textms g.height);
textmsg.graphics.endFill();
addChild( textmsg );
}
}
}
hope that sheds some light. good luck!
01-07-2011 12:02 PM
Thanks. It has to do with the order of the calls (not very OO like). If you try to set the justification after setting the string value with htmlText, the justification is ignored.
I am writing my own AlertDialog class system. I just got tired of not being able to test certain things in AIR. Same API as the QNX, with some additions. Hope to have it released in the next week or so.