Skip to main content
Inspiring
March 5, 2010
Question

adding subscript to XML pulling data via E4X

  • March 5, 2010
  • 1 reply
  • 4052 views

Hi, I am using AS3

and E4X to pull in an XML file. I am wishing to display some text as subscipt. E.G with

G2, the 2 would be subscripted. Any ideas

if this can be done and if so how?


This topic has been closed for replies.

1 reply

Inspiring
March 6, 2010

CS4 and Player 10 have additional package for this kind of things:

flash.text.engine

Otherwise, as for subscript, you can accomplish it with StyleSheet (see code below) - this is not an ideal subscript but some can bare it. As for the superscript or more adequate subscript, things are getting hairier. There are some solution on Internet - search Google. In a nutshell, there are AS3 packages that do that, or one can create such an engine himself or use special fonts that are also available.

var styleSheet:StyleSheet = new StyleSheet();
              
var styleObject:Object = {
     fontFamily: "Arial",
     fontSize: 12
}
styleSheet.setStyle("p", styleObject);
              
styleObject.display = "inline";
styleObject.fontSize = 8;
              
styleSheet.setStyle("sub", styleObject);
              
var textField:TextField = new TextField();
textField.styleSheet = styleSheet;
textField.autoSize = TextFieldAutoSize.LEFT;
              
textField.htmlText = "<p>example with G<sub>subscript</sub> text.";
              
addChild(textField);

Inspiring
March 8, 2010

thanks, with the stylesheet solution, would I just add <sub> and </sub> to the XML file with CDATA?

Inspiring
March 8, 2010

Yes, just add HTML formatted text with CDATA.