Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
584 views
in Technique[技术] by (71.8m points)

actionscript 3 - How to use superscripting in flex?

I want to add a label in flex to display m/s2 (read meters per second square). I would need to use superscripting for this.

I have tried out the following code which is giving me a compilation error.

var richtxt1:RichText = new RichText();
richtxt1.text="m/s";
var richtxt2:RichText = new RichText();
var span:SpanElement = new SpanElement();
span.text = "2";    
span.baselineShift = "superscript"; 
richtxt2.addChild(span);
richtxt1.text=rixhtxt1.txt + richtxt2.text

I am getting a compilation error for the line richtxt2.addChild(span)

The error is

Implicit coercion of a value of type flashX.textLayout.elements.SpanElement 
to unrelated type flash.Display.DisplayObject
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I think you've to do something like this

var xmlText:String = "<TextFlow xmlns='http://ns.adobe.com/textLayout/2008'>" +
                     "m/s <span baselineShift='superscript'>2</span>" +
                     "</TextFlow>";

var txtFlow:TextFlow = TextFlowUtil.importFromXML(xmlText);

var richTxt:RichText = new RichText();
richtxt.textFlow = txtFlow;

I've not tested it so please excuse me of any compilation errors.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...