# Assigning styles to chunks of text

**URL:** <https://forum.kirupa.com/t/assigning-styles-to-chunks-of-text/290487>\
**Category:** flash\
**Created:** [June 15, 2009, 7:26pm UTC](https://forum.kirupa.com/t/assigning-styles-to-chunks-of-text/290487 "2009-06-15T19:26:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdoe](https://avatars.discourse-cdn.com/v4/letter/j/eb8c5e/32.png) [@jdoe](https://forum.kirupa.com/u/jdoe)\
**Post date:** [June 15, 2009, 7:26pm UTC](https://forum.kirupa.com/t/assigning-styles-to-chunks-of-text/290487/1 "2009-06-15T19:26:22Z")

</div>

Hi:

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 /\>]]\>  
…

**AS3**  
…  
setTextFormat();  
setTexto(xmlData.texto);

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;  
…[/INDENT]  
}

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]  
[INDENT]…[/INDENT]  
}

Thanks in advance
