Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...