我有这个控件,mx:Text
,我想为其htmlText
成员分配类似的内容:
<div class="style_header">This text will have, say, Courier as its font</div>
<div class="style_body">And this one will be, oh I dunno, cuneiform</div>
然后,在我的AS中:
var oCSSHeader:CSSStyleDeclaration = new CSSStyleDeclaration;
var oCSSBody:CSSStyleDeclaration = new CSSStyleDeclaration;
oCSSHeader.setStyle('font-size', '12');
oCSSHeader.setStyle('font-family', 'Courier');
oCSSBody.setStyle('font-size', '14');
oCSSBody.setStyle('font-family', 'Cuneiform');
StyleManager.setStyleDeclaration('.style_header', oCSSHeader, true);
StyleManager.setStyleDeclaration('.style_body', oCSSBody, true);
无论我将大小和系列设置为什么,两组文本看起来完全相同。我查看了示例并意识到您可能必须将整个控件设置为一个样式名称。这意味着
<mx:Text id="messageText" width="100%" styleName="style_header" />
应该有效,但它没有!那么我做错了什么?我没有收到任何错误消息或任何内容。甚至可以在一个控件中设置不同的样式名称吗?
我正在运行Flex 3.5
答案 0 :(得分:0)
尝试Text.styleSheet
,
示例:强>
<fx:Script>
<![CDATA[
private function getHtmlTextStyle():StyleSheet
{
var style:StyleSheet = new StyleSheet();
style.setStyle(".style_header", {fontSize: "12px", fontFamily: 'Courier'});
style.setStyle(".style_body", {fontSize: "14px", fontFamily:"Cuneiform"});
return style;
}
]]>
</fx:Script>
<mx:Text id="messageText" width="100%" styleSheet="{getHtmlTextStyle()}">
<mx:htmlText>
<![CDATA[
<p class="style_header">This text will have, say, Courier as its font</p>
<p class="style_body">And this one will be, oh I dunno, cuneiform</p>
]]>
</mx:htmlText>
</mx:Text>
Flex in Flex应用程序不适用于htmlText
它们实际上是分开的,并没有多大关系,只是使用相同的语法。
此外,
Text.htmlText
中允许的标签非常有限。例如,<div>
代码无法使用。有关详细信息,请参阅document。