Assigning styles to chunks of text


I need to assign styles (bold, italic, …) to chunks of text in a textfield with embedded fonts (defaultTextFormat) wich is XML loaded:

  • HTML tags: simply ignored
  • CSS:
    Error #2009: This method cannot be used on a text field with a style sheet.
    at flash.text::TextField/set defaultTextFormat()

I guess I’m ignoring something obvious, it can’t be so difficult! :tired:

XML file
<![CDATA[<span class=“strong”>]]>PRESIDENT<![CDATA[</span><br />]]>



private function setTexto(texto:String):void {
[INDENT]var style:StyleSheet = new StyleSheet();
var strong:Object = new Object();
strong.fontWeight = “bold”;
style.setStyle(".strong", strong);

item_txt = new TextField();
item_txt.styleSheet = style;
item_txt.embedFonts = true;
item_txt.defaultTextFormat = textDef_fmt;

private function setTextFormat() {
[INDENT]//Embedded font in library: Flash CS3[/INDENT]
[INDENT]txtFont = new menuItems();[/INDENT]
[INDENT]textDef_fmt = new TextFormat();[/INDENT]
[INDENT]textDef_fmt.font = txtFont.fontName;[/INDENT]

Thanks in advance