Skip to main content
Participant
February 25, 2009
Answered

CharacterFormat

  • February 25, 2009
  • 2 replies
  • 796 views
Hi,

I have some problems using CharacterFormat. The code below set char color and size, bat not fontFamily or fontWeight.....

quote:


var styleList:String = "Arial,13,0x000000,bold,";

var charFormat:CharacterFormat = new CharacterFormat();
var arrStyles:Array = styleList.split(",");

charFormat.fontFamily = arrStyles[0];
charFormat.fontSize = arrStyles[1];
charFormat.color = arrStyles[2];
charFormat.fontWeight = arrStyles[3];
charFormat.fontStyle = arrStyles[4];
charFormat.fontLookup = flash.text.engine.FontLookup.EMBEDDED_CFF;
charFormat.kerning = flash.text.engine.Kerning.ON;

textFlow.characterFormat = charFormat;

//required to show the style changes
textFlow.flowComposer.updateAllContainers();



Thanks!
This topic has been closed for replies.
Correct answer brian_thomas2
The problem is probably in how you are embedding the font. Make sure you are embedding Arial and specifying the fontFamily as 'Arial'. There is an explanation of how to do this with DefineFont4 over on our blog: Embedded Font Subsetting Using DefineFont4

2 replies

Participant
February 26, 2009
This is the code, i'm not able to find the problem.... :(

quote:


package classes{

//IMPORTS ####################
import flash.display.*;
import flash.events.MouseEvent;
import flash.text.engine.FontPosture;
import flash.text.engine.Kerning;

import flashx.textLayout.compose.StandardFlowComposer;
import flashx.textLayout.container.DisplayObjectContainerController;
import flashx.textLayout.container.IContainerController;
import flashx.textLayout.elements.*;
import flashx.textLayout.conversion.TextFilter;
import flashx.textLayout.events.*;
import flashx.textLayout.formats.*;
import flashx.textLayout.conversion.ConversionType;

public class textFlowBuilder extends Sprite {

public var textFlow:TextFlow = new TextFlow;
//create object
public function textFlowBuilder(xmlList:XMLList, w:Number, h:Number) {
//get only the first <textFlow> tag (1 <textFlow> for each <textField>
var xmlText:XML=xmlList[0];
textFlow=TextFilter.importToFlow(xmlText,TextFilter.TEXT_LAYOUT_FORMAT);
textFlow.flowComposer.addController(new DisplayObjectContainerController(this, w, h));
textFlow.flowComposer.updateAllContainers();

//create a listener for any click into the textbox (TextFlow);
textFlow.addEventListener("click", linkHandler);
}

//SET STYLE ############################
public function setFlowStyle(styleList:String):void{
var charFormat:CharacterFormat = new CharacterFormat();
var arrStyles:Array = styleList.split(",");

//charFormat prop.
charFormat.fontFamily = arrStyles[0];
charFormat.fontSize = arrStyles[1];
charFormat.color = arrStyles[2];
charFormat.fontWeight = arrStyles[3];
charFormat.fontStyle = arrStyles[4];
charFormat.fontLookup = flash.text.engine.FontLookup.EMBEDDED_CFF;
charFormat.kerning = flash.text.engine.Kerning.ON;

//textFlow prop.
textFlow.textAlign = arrStyles[5];

//add format
textFlow.characterFormat = charFormat;

//required to show the style changes
textFlow.flowComposer.updateAllContainers();
}

}//end class
}//end package

brian_thomas2
Adobe Employee
brian_thomas2Correct answer
Adobe Employee
March 6, 2009
The problem is probably in how you are embedding the font. Make sure you are embedding Arial and specifying the fontFamily as 'Arial'. There is an explanation of how to do this with DefineFont4 over on our blog: Embedded Font Subsetting Using DefineFont4
Adobe Employee
February 26, 2009
I tried this similar example, and it seems to be working:

package {
import flash.display.Sprite;
import flash.text.engine.ElementFormat;
import flash.text.engine.TextBlock;
import flash.text.engine.TextElement;
import flash.text.engine.TextLine;

import flashx.textLayout.elements.TextFlow;
import flashx.textLayout.formats.TextLayoutFormat;
import flashx.textLayout.conversion.TextFilter;
import flashx.textLayout.container.DisplayObjectContainerController;

public class HelloWorld extends Sprite
{
public function HelloWorld()
{
var styleList:String = "Arial,13,0x000000,bold,";

var charFormat:TextLayoutFormat = new TextLayoutFormat();
var arrStyles:Array = styleList.split(",");

charFormat.fontFamily = arrStyles[0];
charFormat.fontSize = arrStyles[1];
// charFormat.color = arrStyles[2];
charFormat.fontWeight = arrStyles[3];
charFormat.fontStyle = arrStyles[4];
charFormat.fontLookup = flash.text.engine.FontLookup.EMBEDDED_CFF;
charFormat.kerning = flash.text.engine.Kerning.ON;

var textFlow:TextFlow = TextFilter.importToFlow("Hi there", TextFilter.PLAIN_TEXT_FORMAT);
textFlow.textLayoutFormat = charFormat;
var sprite:Sprite = new Sprite();
addChild(sprite);
textFlow.flowComposer.addController(new DisplayObjectContainerController(sprite, 200, 200));

//required to show the style changes
textFlow.flowComposer.updateAllContainers();
}
}
}

I'm using device fonts, so its a little different, but all the format settings are coming through OK. I wonder if your problems are related to the embedded font? You could try it with a device font and see if it appears as you expect. If so, something is going wrong with the embedding.