Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

adding subscript to XML pulling data via E4X

Explorer ,
Mar 05, 2010 Mar 05, 2010

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?


TOPICS
ActionScript
4.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 06, 2010 Mar 06, 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);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 08, 2010 Mar 08, 2010

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 08, 2010 Mar 08, 2010

Yes, just add HTML formatted text with CDATA.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 08, 2010 Mar 08, 2010

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 08, 2010 Mar 08, 2010

This is a sample text. Replace it with text value that comes with xml.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 08, 2010 Mar 08, 2010

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>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 08, 2010 Mar 08, 2010

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>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 08, 2010 Mar 08, 2010

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.";
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 08, 2010 Mar 08, 2010

I am not sure I understand the question.


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 08, 2010 Mar 08, 2010

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

?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 08, 2010 Mar 08, 2010

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>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 08, 2010 Mar 08, 2010

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 08, 2010 Mar 08, 2010

Yes, as I described in one of earlier posts, you have to set StyleSheet to text field(s) with corresponding objects and value.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 08, 2010 Mar 08, 2010
LATEST

thanks, I will give it a try and let you know how it turns out.


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines