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
New Developer
backslash
Posts: 12
Registered: ‎11-10-2011
My Device: Z10
My Carrier: not important
Accepted Solution

How embed fonts in TextInput with AS3

I have this code

 

public class PixelTextInput extends TextInput
	{
		
		[Embed(source="../data/uni05_54.ttf", fontFamily="UniFont", mimeType="application/x-font-truetype")]private const UniFont:Class;
		
		public function PixelTextInput()
		{
			super();
			var uniFont:Font = new UniFont();
			var textFormat:TextFormat = new TextFormat();
			textFormat.color = 0xFF0000;
			textFormat.font = uniFont.fontName;
			textFormat.size = 12;
			this.format = textFormat;
			
		}
	}

 

 

I successfully embedded a font in a LabelButton and a Label but both have this property:

this.embedFonts = true;

 The TextInput however doesn't have that and perhaps that's why it ignores the font but not the color.

 

So does anyone know how to embed a font within a TextInput (a qnx.fuse.ui.text.TextInput)?

Thanks in advance!!

 

 

 

 

Please use plain text.
BlackBerry Development Advisor (Retired)
dmalik
Posts: 427
Registered: ‎02-22-2012
My Device: BlackBerry Z10, BlackBerry Dev Alpha C, BlackBerry PlayBook
My Carrier: Bell

Re: How embed fonts in TextInput with AS3

Hi,

 

This code should have what you're looking for :smileyhappy:

 

package
{
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.text.TextFormat;
	
	import qnx.fuse.ui.text.Label;
	import qnx.fuse.ui.text.TextFormat;
	import qnx.fuse.ui.text.TextInput;
	
	[SWF(height="600", width="1024", 
    frameRate="30", backgroundColor="#FFFFFF")]
	
	public class LargerInputTest extends Sprite
	{
		//Create textinput, label and format
		private var myText:TextInput = new TextInput();
		private var myTextFormatInput:qnx.fuse.ui.text.TextFormat = new qnx.fuse.ui.text.TextFormat();
		private var myTextFormatLabel:flash.text.TextFormat = new flash.text.TextFormat();
		private var firstLabel:Label = new Label();
		
		public function LargerInputTest()
		{
			initializeUI();
		}
		
		private function initializeUI():void
		{
			//Create and position text input
			myText.height = 100;
			myText.width = 500;
			myText.x = stage.stageWidth*.5 - myText.width*.5;
			myText.y = stage.stageHeight*.5 - myText.height*.5 -100;
			myText.text = "£ § â é ñ ú";
			
			//Style
			myTextFormatInput.font = "Arial";
			myTextFormatInput.size = 36;
			
			//Assign style
			myText.format = myTextFormatInput;
		
			//Add to stage
			addChild(myText);
			
			//Create and position label
			firstLabel.text = "First lábel";
			firstLabel.height = 100;
			firstLabel.width = 500;
			firstLabel.x = stage.stageWidth*.5 - firstLabel.width*.5;
			firstLabel.y = stage.stageHeight*.5 - firstLabel.height*.5 - 150;
			
			//style label
			myTextFormatLabel.font = "Arial";
			myTextFormatLabel.size = 36;
			
			//assign style
			firstLabel.format = myTextFormatLabel;
			
			//add label
			addChild(firstLabel);
		}
	}
}

 

Follow me on Twitter: @dustinmalik
-----------------------------------------------------------------------------------------------------
Keep up to date on BlackBerry development: http://devblog.blackberry.com/
Please use plain text.
New Developer
backslash
Posts: 12
Registered: ‎11-10-2011
My Device: Z10
My Carrier: not important

Re: How embed fonts in TextInput with AS3

Thanks a lot for your code but my problem is not that I can't change the font of the TextInput if its a 'normal' font like Arial or Times New Roman and so on. My Problem is, if I want to use a embedded font the TextInput ignores it and uses a standard font instead. So I try to embed a font with

[Embed(source="../data/uni05_54.ttf", fontFamily="UniFont", mimeType="application/x-font-truetype")]private const UniFont:Class;

 and after that I use this

var myTextInput:TextInput = new TextInput();
var textFormat:TextFormat = new TextFormat();
textFormat.color = 0xFF0000;
textFormat.font = uniFont.fontName;
myTextInput.format = textFormat;

 but it still uses a normal font but with the color I declare.

 

So thanks again and I hope you have another solution for me...

 

Please use plain text.
New Developer
backslash
Posts: 12
Registered: ‎11-10-2011
My Device: Z10
My Carrier: not important

Re: How embed fonts in TextInput with AS3

I tried it now with the old qnx.ui.text.TextInput and there is a property 'embedFonts'. Now it is working but it would be nicer if I could use the qnx.fuse.ui.text.TextInput. So perhaps somebode knows a solution but since then I will be good with it.

Please use plain text.
BlackBerry Development Advisor (Retired)
dmalik
Posts: 427
Registered: ‎02-22-2012
My Device: BlackBerry Z10, BlackBerry Dev Alpha C, BlackBerry PlayBook
My Carrier: Bell

Re: How embed fonts in TextInput with AS3

[ Edited ]

Because the Flash and QNX classes use the same name you have to explicitly declare them. You only need to do this for the fuse components.

 

private var myTextFormatInput:qnx.fuse.ui.text.TextFormat = new qnx.fuse.ui.text.TextFormat();
private var myTextFormatLabel:flash.text.TextFormat = new flash.text.TextFormat();

Follow me on Twitter: @dustinmalik
-----------------------------------------------------------------------------------------------------
Keep up to date on BlackBerry development: http://devblog.blackberry.com/
Please use plain text.