PDA

View Full Version : Style htmlText on Text-component?


Pipan
11-10-2008, 10:53 PM
So, I have a <mx:Text> component. This is "populated" with htmlText from a webservice.

This html-text of course have tags like <p>, <h1> and <strong>
How do I create styles for these tags without destroyin the antialias?

Since I cant use StyleSheet-class on this component and I need to use a Replace-method in the Webservice:

output.Replace("h1", "<font size=15>");

And this freaks up my nice text (blury headers), and I cant use padding on those elements, and therefor have to add ugly <br> - tags before and after headers. Not nice.

Tell me there are better ways of doing this with flex?
I wanna use my project's css-file.

Pipan
11-14-2008, 10:52 PM
To simplify my question;

How do I add styles for headers (<h1>) on a mx:Text - component?

ljuwaidah
11-15-2008, 05:23 AM
I'm not quite sure but if you use xml-compatible html you might be able to use xml functions to do what you want.

drkstr
11-15-2008, 07:36 PM
var style:StyleSheet = new StyleSheet();

var styleObj:Object = new Object();
styleObj.fontSize = 16;
styleObj.fontWeight = "bold";

style.setStyle("h1", styleObj);

var ta:TextArea = new TextArea();
ta.styleSheet = style;
ta.htmlText = "<h1>Some Text</h1>";


Best Regards,
~Aaron

Pipan
11-16-2008, 03:02 AM
Yes that is possible on TextArea-component, but not on the Text-component,
because it doesnt have any styleSheet-property.

:confused:

drkstr
11-18-2008, 01:12 AM
Ah yes, that's a bummer, sorry. Guess it was not the intended use of the Text component to have multiple style declarations. Even though your only using one line, the StyleSheet class is really meant for multi-line text and the Text component is intended for single line (event though it wraps). You could always create a TextArea and make it act like a Text component. But even still, you might not get the results you intend (such as extra line breaking on headers). RegExp replacements are probably your best bet. Why are you getting fuzzy headers? Are you using the correct <FONT family="yourEmbededFont"> ?


Best Regards,
~Aaron