Skip to main content
Known Participant
September 9, 2009
Question

Read href tag HELP !!

  • September 9, 2009
  • 1 reply
  • 2634 views

I have : <p ><a href="http://www.example.com" target="_blank"><span>link example</span></a></p> into TextFlow

I need  collect the href data to an textInput when select  'link example' words.

I add a Listener:

TextFlow.addEventListener(SelectionEvent.SELECTION_CHANGE,selectionChangeListener,false,0,true);

and :

private function selectionChangeListener(evt:SelectionEvent):void
             {

                 /// how can I read href tag  ?

                        myTxt.text = evt ???????

              }

thanks

This topic has been closed for replies.

1 reply

Known Participant
September 10, 2009

Hi!

... it is big sh*t reading the href proprerty... but it works for me...=)

... the basic is that you have to find in the textFlow the LinkElement, check is it in the selection range, and if yes, that it is very easy to read the href property of it ... =)

        private function getLinkPropertyInTheSelectionRange():String
        {
                    if (selectedElementRange.firstParagraph == selectedElementRange.lastParagraph)
                        if (selectedElementRange.firstParagraph.numChildren == 1)
                            return selectedElementRange.firstParagraph.getChildAtIndex(0) is LinkElement ?
                                LinkElement(selectedElementRange.firstParagraph.getChildAtIndex(0)).href :
                                null;
                        else
                            for (var i:int = selectedElementRange.firstParagraph.numChildren; i-- > 0;)
                            {
                                if (selectedElementRange.firstParagraph.getChildAtIndex(i) is LinkElement &&
                                    elementIsInTheSelection(selectedElementRange.firstParagraph.getChildAtIndex(i)))
                                        return LinkElement(selectedElementRange.firstParagraph.getChildAtIndex(i)).href;
                            }
                    return null;

        }


        private function elementIsInTheSelection(flowElement:FlowElement):Boolean
        {
            var absoluteStart:int = flowElement.getAbsoluteStart();

            var isIn:Boolean =
                    selectedElementRange.absoluteStart == selectedElementRange.absoluteEnd ?
                        absoluteStart < selectedElementRange.absoluteStart &&
                        absoluteStart - flowElement.parentRelativeStart + flowElement.parentRelativeEnd > selectedElementRange.absoluteEnd:
                        absoluteStart <= selectedElementRange.absoluteStart &&
                        absoluteStart - flowElement.parentRelativeStart + flowElement.parentRelativeEnd >= selectedElementRange.absoluteEnd;

//            trace('        TextEditor.elementIsInTheSelection    ',
//                flowElement,'\t',isIn,absoluteStart,'\t',
//                absoluteStart + flowElement.parentRelativeStart,    selectedElementRange.absoluteStart,        '\t',
//                selectedElementRange.absoluteEnd,                    absoluteStart + flowElement.parentRelativeEnd);

            return isIn;
        }

ErnIvanAuthor
Known Participant
September 10, 2009

Great !!!!!!

yes It is big ...but  WORKS

many Thanksssss