Skip to main content
Participant
February 25, 2011
Question

chemical formula in RichEditableText

  • February 25, 2011
  • 1 reply
  • 873 views

Hi,

for chemical formulars in my application I need to convert the <sub> tag.
I get the formula from the DataBase. I am able to display the formula but not to edit, because every part stays single.
I would need to merge them to a group but I don't know how. I tried some different ways but nothing works.

// variable with content from DataBase
var txtFormulaXMLFOTemp:String = "";

while(txtFormulaXMLFOTemp.length > 0){                       
                           
    formulaXMLFOSubStart = txtFormulaXMLFOTemp.search("<sub>" );
    formulaXMLFOSubEnd = txtFormulaXMLFOTemp.search("</sub>");
                       
    if(formulaXMLFOSubStart > -1 && formulaXMLFOSubEnd > -1 && (formulaXMLFOSubEnd > formulaXMLFOSubStart)){
                                           
        txtFormulaXMLFO = txtFormulaXMLFOTemp.substring(0, formulaXMLFOSubStart);
        txtFormulaXMLFOStart = txtFormulaXMLFO;
        txtFormulaXMLFOSub = txtFormulaXMLFOTemp.substring((formulaXMLFOSubStart + 5), formulaXMLFOSubEnd);
        txtFormulaXMLFOTemp = txtFormulaXMLFOTemp.substring((formulaXMLFOSubEnd + 6), txtFormulaXMLFOTemp.length);

        var richTxtFormulaFOStart:RichEditableText;
        richTxtFormulaFOStart = new RichEditableText();
        richTxtFormulaFOStart.text = txtFormulaXMLFOStart;
        hGroupEditView.addElement(richTxtFormulaFOStart);

        var richTxtFormulaFOSub:RichEditableText;
        richTxtFormulaFOSub = new RichEditableText();
        richTxtFormulaFOSub.text = txtFormulaXMLFOSub;
        richTxtFormulaFOSub.textFlow.baselineShift = "subscript";
        richTxtFormulaFOSub.textFlow.dominantBaseline = "ascent";
        richTxtFormulaFOSub.validateNow();
        hGroupEditView.addElement(richTxtFormulaFOSub);
    }   
    else{
        txtFormulaXMLFO = txtFormulaXMLFOTemp;
        txtFormulaXMLFOEnd = txtFormulaXMLFO;
        var richTxtFormulaFOEnd:RichEditableText;
        richTxtFormulaFOEnd = new RichEditableText();
        richTxtFormulaFOEnd.text = txtFormulaXMLFOEnd;
        hGroupEditView.addElement(richTxtFormulaFOEnd);                                           
    }
   
<s:HGroup id="hGroupEditView" x="0"  gap="0" width="100%" alignmentBaseline="descent" textAlign="left" mouseEnabled="true">

    <s:RichEditableText id="editorFO"
        maxHeight="20"
        focusEnabled="false"
        editable="true"
        multiline="false"
        breakOpportunity="none"
        selectionChange="editor_selectionChangeHandler(event);"
        change="setDisplayEdit(event)">
    </s:RichEditableText>
</s:HGroup>

My future goal:
Below "editorFO" is a ButtonBarButton with some further possibilities to change the formula (bold, underline, add greek letters).

That works like shown in other examples:
    protected function subBtn_clickHandler(evt:MouseEvent):void {
        var txtLayFmt:TextLayoutFormat = editor.getFormatOfRange(null,
        editor.selectionAnchorPosition,
        editor.selectionActivePosition);
        txtLayFmt.baselineShift = (txtLayFmt.baselineShift == BaselineShift.SUBSCRIPT ? BaselineShift.SUBSCRIPT : BaselineShift.SUBSCRIPT);
        editor.setFormatOfRange(txtLayFmt,
        editor.selectionAnchorPosition,
        editor.selectionActivePosition);
        editor.setFocus();
    }  

Any help is most appreciated.

Thanks, Ellen

This topic has been closed for replies.

1 reply

Adobe Employee
February 28, 2011

So you are getting some markup from a database with <sub>, allowing editing, and then exporting back to the database with <sub> again? When the formula comes in from the database, is it in HTML?

If you are using Flex Hero, the content of the <sub> element will come in as a FlowElement with typeName "sub". You can do a quick search through the RichEditableText content, looking for child FlowElements with typeName == sub and applying a baselineShift to those elements. On export, these elements will be exported as "sub".

If you are using an older version of Flex (and therefore an older version of TLF), it's a little trickier because the "sub" is not preserved on import, although its contents are. So once it has been imported there is no way to know what was marked in a sub element. Getting around this limitation is possible but will require a fair amount of work, so if you can upgrade to Hero, that's your easiest path to a solution.

- robin

EllenFlexAuthor
Participant
March 1, 2011

Hi Robin,

thank you very much for your quick answer.

I didn't know about typeName="sub", but found some infos under: http://blogs.adobe.com/tlf/. I will check that.

Thanks for the keyword.

greetings,

Ellen

Adobe Employee
March 1, 2011