Skip navigation
Currently Being Moderated

Problem with SelectionState, plase help

Apr 1, 2012 9:44 PM

Tags: #textlayout #textflow #as3 #textlayoutframework


I've tried create list and convert it to plain text at runtime.

With creating text evrething is ok    


     var tf:TextLayoutFormat = editor.getFormatOfRange(null, editor.selectionAnchorPosition, editor.selectionActivePosition);    

     var selState : SelectionState = new SelectionState(editor.textFlow, editor.selectionAnchorPosition, editor.selectionActivePosition);

     var listFormar : TextLayoutFormat = tf;

     listFormar.listStyleType = ListStyleType.DISC;

     listFormar.listStylePosition = ListStylePosition.OUTSIDE;

     var operation : CreateListOperation = new CreateListOperation(selState, null, listFormar);



With this evtething is ok - list was created.


But when I've tried to convert selected text from list to plain text I have problem. I've selected list but SelectedState return all textFlow from editor (RichEditableText), and I can't receive root list element. Please help to select list in textFlow.

var selState : SelectionState = new SelectionState(editor.textFlow, editor.selectionAnchorPosition, editor.selectionActivePosition);

  • Currently Being Moderated
    Apr 4, 2012 11:07 PM   in reply to anton.zhuk

    I pasted a code scrap of how to enumerate the listElements. Hope it will be helpful


    //this test case will check up to three level nested lists

                                  //create three lists




                                  var tf:TextFlow = SelManager.textFlow;

                                  var listsFound:int = 0;

                                  var elem:FlowElement = tf.getChildAt(0);

                                  while (elem)


                                            if (elem as ListElement)


                                                      var listElement:ListElement = elem as ListElement;

                                                      var allListElement:Array = [];

                                                      var a:int = 0;

                                                      allListElement[a] = listElement;

                                                      var elem2:FlowElement = listElement.getChildAt(0);

                                                      var e:FlowGroupElement = FlowGroupElement (elem2);

                                                      var i:int=0;

                                                      while (i < e.mxmlChildren.length)


                                                                if (e.mxmlChildren[i] as ListElement)


                                                                          var listElement1:ListElement = e.mxmlChildren[i] as ListElement;

                                                                          var elem3:FlowElement = listElement1.getChildAt(0);

                                                                          var e1:FlowGroupElement = FlowGroupElement (elem3);

                                                                          var j:int=0;

                                                                          while (j < e1.mxmlChildren.length)


                                                                                    if (e1.mxmlChildren[j] as ListElement)




                                                                                              allListElement[a] = e1.mxmlChildren[j] as ListElement;






                                                                          allListElement[a] = e.mxmlChildren[i] as ListElement;






                                            elem = elem.getNextSibling();




                                  // determine what the bullet text should be

                                  var listItem:ListItemElement = new ListItemElement();

                                  var bulletText:String = "";

                                  var markerLength:int = 0;

                                  var listStartIndex:int = 0;

                                  var listFlowLine:TextFlowLine;

                                  var listLine:TextLine;

                                  var bulletLine:TextLine;

                                  for (i=0; i<listsFound; i++)


                                            listElement = allListElement[i] as ListElement;

                                            listItem = listElement.getChildAt(0) as ListItemElement;

                                            bulletText = listElement.computeListItemText(listItem, listItem.computedListMarkerFormat());

                                            markerLength = bulletText.length + 1;

                                            // find the TextFlowLine for the list start

                                            listStartIndex = listElement.getElementRelativeStart(tf);

                                            listFlowLine = tf.flowComposer.findLineAtPosition(listStartIndex);

                                            listLine = listFlowLine.getTextLine();

                                            bulletLine = listLine.getChildAt(0) as TextLine;



    Mark as:
  • Currently Being Moderated
    Apr 5, 2012 11:20 PM   in reply to anton.zhuk

    There will be only one textFlow in your case. It's the container of all the text elements. The selection state represents the selection in 'that' text flow.


    The selection state will record the position information of your selection. You should get use the position information to retrieve your text flow elements

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points