Label

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Label

ScottM
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
Reply | Threaded
Open this post in threaded view
|

Re: Label

Olaf Krueger
>  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/
Reply | Threaded
Open this post in threaded view
|

Re: Label

ScottM
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 <[hidden email]> 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/

Reply | Threaded
Open this post in threaded view
|

Re: Label

Erik Thomas
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.

Reply | Threaded
Open this post in threaded view
|

Re: Label

Erik Thomas
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);
Reply | Threaded
Open this post in threaded view
|

Re: Label

ScottM
thanks that works


> On 19 Sep 2018, at 18:23, Erik Thomas <[hidden email]> 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);