flash as3 xml cdata bold tags rendered in htmlText with an embedded font

夙愿已清 提交于 2020-01-17 01:22:11

问题


I'm just trying to get flash to render bold text in a dynamic text field with an embedded font, using data I've imported from an xml file using CDATA. Anyone know how to do this?

XML File:

<description><![CDATA[ FOR THE PAST TWO YEARS, <b>SUPERFAD</b> HAS WORKED CLOSELY WITH THE <b>MARTIN AGENCY</b> TO VISUALIZE THE ORIGINAL WORKS OF <b>SPORT CAMPAIGN</b>. THE CAMPAIGN SPOTLIGHTS THE EXTREME ATHLETES OF THE VARIOUS EVENTS AS ARTISTS IN THEIR OWN WORLD, USING THE TOOLS OF THEIR SPORT TO CREATE LASTING WORKS OF ART]]></description>

and as3 code:

project_desc = myXML.projects.project[cp].description.toUpperCase();
container.header.t_desc.htmlText = project_desc;

回答1:


Wrap the text you want to be bold in span tags with a class name.

<description><![CDATA[ FOR THE PAST TWO YEARS, <span class="myBoldText">SUPERFAD</span> HAS WORKED...</description>

Then use a StyleSheet object to style it within your actionScript.

var my_styleSheet = new StyleSheet();
var n:Object = new Object();
n.fontWeight = 'bold';
my_styleSheet.setStyle('.myBoldText', n);
container.header.t_desc.styleSheet = my_styleSheet;
container.header.t_desc.htmlText = project_desc;

Don't forget to import the styleSheet class!

import flash.text.StyleSheet;

More info on the StyleSheet class here: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/StyleSheet.html



来源:https://stackoverflow.com/questions/5035098/flash-as3-xml-cdata-bold-tags-rendered-in-htmltext-with-an-embedded-font

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!