adding subscript to XML pulling data via E4X
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
CS4 and Player 10 have additional package for this kind of things:
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);
Copy link to clipboard
Copied
thanks, with the stylesheet solution, would I just add <sub> and </sub> to the XML file with CDATA?
Copy link to clipboard
Copied
Yes, just add HTML formatted text with CDATA.
Copy link to clipboard
Copied
I don't understand this part
textField.htmlText = "<p>example with G<sub>subscript</sub> text.
since I am pulling the data via XML what would I need this for?
Copy link to clipboard
Copied
This is a sample text. Replace it with text value that comes with xml.
Copy link to clipboard
Copied
hmm, but this is an exam I am working on and there are many instances with subscripts. Like below except x 20
<QUESTION>During the G<![CDATA["<sub>2</sub>"]]> phase of the cell cycle, the cell </QUESTION>
Copy link to clipboard
Copied
This is a wrong way to use CDATA. Here is how you must use it - it has to encompass entire node text value:
<QUESTION><![CDATA[During the G<sub>2</sub> phase of the cell cycle, the cell ]]></QUESTION>
Also, since now it is HTML, you should use html tags in the text. Something like this:
<QUESTION><![CDATA[<p>During the G<sub>2</sub> phase of the cell cycle, the cell</p>]]></QUESTION>
Copy link to clipboard
Copied
ok thanks, but do I have to do a different instance of below in the AS3 for each question with a subscript involved?
textField.htmlText = "<p>example with
G<sub>subscript</sub> text.";
Copy link to clipboard
Copied
I am not sure I understand the question.
Copy link to clipboard
Copied
ok, here is an example of a node in my XML
<SECTION id="1">
<PROBLEM id="1">
<QUESTION>During the G2 phase</QUESTION>
<CHOICE letter="a">G1</CHOICE>
<CHOICE letter="b" correct="true">G2</CHOICE>
<CHOICE letter="c">G3</CHOICE>
<CHOICE letter="d">G4</CHOICE>
</PROBLEM>
<PROBLEM id="2">
<QUESTION>Which of the following phases of the cell cycle represents a resting phase?</QUESTION>
<CHOICE letter="a" correct="true">G1</CHOICE>
<CHOICE letter="b">G2</CHOICE>
<CHOICE letter="c">G3</CHOICE>
<CHOICE letter="d">G4</CHOICE>
</PROBLEM>
</SECTION>
Each question and answer may have a subscript.
first question, can I put the CDATA at the begining/end of the SECTION? and how would I code what I need in AS3 with the :
textField.htmlText
?
Copy link to clipboard
Copied
It feels like there is a need to polish your XML structure understanding. Here is one of the links that explains CDATA:
http://en.wikipedia.org/wiki/CDATA
CDATA in XML is a node value wrapper. In your case you should wrap all the values into CDATA individually on per node basis. And each node value should be constructed as an HTML block. Cases that have subscript will need be surrounded by <sub> tag.
<QUESTION><![CDATA[<p>During the G<sub>2</sub> phase</p>]]</QUESTION>
<CHOICE letter="a"><![CDATA[<p>G<sub>1</sub></p>]]</CHOICE>
Copy link to clipboard
Copied
ok, thanks. understand what I need to do with CDATA now. Do I need to add anything
to the AS3 (other than what you already provided) based on what I provided as
a sample of my XML?
Copy link to clipboard
Copied
Yes, as I described in one of earlier posts, you have to set StyleSheet to text field(s) with corresponding objects and value.
Copy link to clipboard
Copied
thanks, I will give it a try and let you know how it turns out.

