04-29-2012 03:10 AM
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!!
Solved! Go to Solution.
05-01-2012 12:05 PM
Hi,
This code should have what you're looking for ![]()
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);
}
}
}
05-02-2012 05:47 PM
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...
05-02-2012 06:15 PM
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.
05-03-2012 09:18 AM - edited 05-03-2012 09:21 AM
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();