Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Developer
Posts: 138
Registered: ‎01-09-2011
My Device: Blackberry Tablet OS
Accepted Solution

Text Size of TextFormat not working

Hello, I am using this code to create a window which will be used for the settings dialog in my application.

 

 

private function createSettings():void{
			sw = new Sprite();
			sw.visible = false;
			sw.graphics.beginFill(0xCCCCCC,0.9);
			var pos_x:Number = (stage.stageWidth - 712)/2;
			var pos_y:Number = (stage.stageHeight - 400)/2;
			 sw.graphics.drawRoundRect(pos_x,pos_y,712,400,100,100);
			sw.graphics.endFill();
			
			var formatSettingsTitle:TextFormat = new TextFormat();
			formatSettingsTitle.align = "center";
			formatSettingsTitle.bold = true;
			formatSettingsTitle.color = 0x000000;
			formatSettingsTitle.size = 72;
			
			var lblSettingsTitle:TextField = new TextField();
			lblSettingsTitle.selectable = false;
			lblSettingsTitle.setTextFormat(formatSettingsTitle);
			lblSettingsTitle.autoSize = TextFieldAutoSize.CENTER;
			lblSettingsTitle.text = "Settings";
			lblSettingsTitle.x = (sw.width - lblSettingsTitle.width)/2;
			lblSettingsTitle.y = pos_y + 20;
			sw.addChild(lblSettingsTitle);
			
			addChild(sw);
		}

 

A gray rounded box is being created but the size of the text located inside of it is 12. Why won't the size of the text change?

 

From,
Noah NU
Developer
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Text Size of TextFormat not working

hey,

 

try using the defaultTextFormat property of the TextField object along with the setTextFormat property like this:

 

 

private function createSettings():void{
sw = new Sprite();
sw.visible = false;
sw.graphics.beginFill(0xCCCCCC,0.9);
var pos_x:Number = (stage.stageWidth - 712)/2;
var pos_y:Number = (stage.stageHeight - 400)/2;
sw.graphics.drawRoundRect(pos_x,pos_y,712,400,100,100);
sw.graphics.endFill();

var formatSettingsTitle:TextFormat = new TextFormat();
formatSettingsTitle.align = "center";
formatSettingsTitle.bold = true;
formatSettingsTitle.color = 0x000000;
formatSettingsTitle.size = 72;

var lblSettingsTitle:TextField = new TextField();
lblSettingsTitle.selectable = false;
lblSettingsTitle.setTextFormat(formatSettingsTitle);
lblSettingsTitle.defaultTextFormat = formatSettingsTitle;
lblSettingsTitle.autoSize = TextFieldAutoSize.CENTER;
lblSettingsTitle.text = "Settings";
lblSettingsTitle.x = (sw.width - lblSettingsTitle.width)/2;
lblSettingsTitle.y = pos_y + 20;
sw.addChild(lblSettingsTitle);

addChild(sw);
}

 

Hope that helps. good luck!

 

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Developer
Posts: 138
Registered: ‎01-09-2011
My Device: Blackberry Tablet OS

Re: Text Size of TextFormat not working

Thanks, it now works.

 

Is there an explanation as to why that works? Since I have used the setTextFormat before and it has worked on various other occasions without the need to set the defaultTextFormat.

 

Thanks,

Noah NU

From,
Noah NU
Developer
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Text Size of TextFormat not working

ahh yeah! sorry about that totally spaced out and forgot to explain. the setTextFormat method formats the text thats already in the textfield. and the defaultTextFormat property formats all the texts you add to the textfield afterwards. Since in your code you are setting the text of the TextField object after you used the setTextFormat method, it didnt apply the format to the newly added text. hope that clears things up. again my bad  Smiley Happy good luck!

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman