You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by Scott Matheson <sc...@matheson.it> on 2018/09/19 14:19:15 UTC

Label

Hi
     How do I make a text label appear in the center of an lable using AS3 code
 
     var _lsn:Label = new Label();
     _lsn.text = _”hellow”
     _lsn.setStyle("textAlign", "center");
 
 
the issue must be setStyle 
 
Scott

Re: Label

Posted by scott matheson <sc...@matheson.it>.
thanks that works 


> On 19 Sep 2018, at 18:23, Erik Thomas <er...@icloud.com> wrote:
> 
> Another option is to center all objects in the parent container, but the parent container must also set width or percentWidth. When width is not specified, a container or Label will size to fit the content only, so there is no concept of centering.
> 
> var _sln:Label = new Label();
> _sln.text = _uofsModel.tempLessonTestResults.aUofS[i];
> _bgs.setStyle("horizontalAlign", "center"); 
> _bgs.width = 800;
> _bgs.addElement(_sln);


Re: Label

Posted by Erik Thomas <er...@icloud.com>.
Another option is to center all objects in the parent container, but the parent container must also set width or percentWidth. When width is not specified, a container or Label will size to fit the content only, so there is no concept of centering.

var _sln:Label = new Label();
_sln.text = _uofsModel.tempLessonTestResults.aUofS[i];
_bgs.setStyle("horizontalAlign", "center"); 
_bgs.width = 800;
_bgs.addElement(_sln);

Re: Label

Posted by Erik Thomas <er...@icloud.com>.
For text to be centered, the width of the Label must be set. You can set it to percent value or points with percentWidth or width properties.

var _sln:Label = new Label();
_sln.text = _uofsModel.tempLessonTestResults.aUofS[i];
_sln.setStyle("textAlign", "center");
_sin.percentWidth = 100;
_bgs.addElement(_sln);

Using 100% width will center it in the parent container's x axis.


Re: Label

Posted by Scott Matheson <sc...@matheson.it>.
yes the width works fine 

var _sln:Label = new Label();
_sln.text = _uofsModel.tempLessonTestResults.aUofS[i];
_sln.setStyle("textAlign", "center");
_bgs.addElement(_sln);






> On 19 Sep 2018, at 16:06, Olaf Krueger <ma...@olafkrueger.net> wrote:
> 
>> How do I make a text label appear in the center of an lable using AS3 code
> 
> Did you try to also set the width of the label?
> IIRC the alignment only works in conjunction with a width?
> 
> HTH,
> Olaf
> 
> 
> 
> --
> Sent from: http://apache-flex-users.2333346.n4.nabble.com/


Re: Label

Posted by Olaf Krueger <ma...@olafkrueger.net>.
>  How do I make a text label appear in the center of an lable using AS3 code

Did you try to also set the width of the label?
IIRC the alignment only works in conjunction with a width?

HTH,
Olaf



--
Sent from: http://apache-flex-users.2333346.n4.nabble.com/