On 5/5/07, b_alen <[EMAIL PROTECTED]> wrote:
> I have a string that goes somthing like this:
>
> var str:String = "<p class=\"H1\">section</p>";
> var str:String += "<p class=\"TXT\">main text</p>";
>
> and then I populate the Text component like this:
>
> txtPage.htmlText = str;
>
> Now, I want to add styles to this text through class attributes that I
> provided in the HTML. In Flash 8 this is pretty straightforward but I
> couldn't figure out how to do it in Flex.

In Flex too you can do it in the Flash way, i.e. by setting the
styleSheet property.

  import mx.core.mx_internal;

  myTextObject.mx_internal::styleSheet = myStyleSheetObject;

Note: The styleSheet property in Label and Text is in the mx_internal
namespace -- it's not public API. I guess this is due to the
inconsistency between Flash and Flex styling. If you don't want to use
mx_internal, you can do it by making a subclass of Text.

  public MyText extends Text {
    public function setStyleSheet(styleSheet:StyleSheet):void {
      textField.styleSheet = styleSheet;
    }
    public function getStyleSheet():StyleSheet {
      return textField.styleSheet;
    }
  }

Reply via email to