Skip to main content
Known Participant
Sep 9, 2009 9:18 AM UTC
Question

Read href tag HELP !!

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 is closed to new replies. Start a new post to keep the conversation going.

15 replies

Known Participant
Sep 10, 2009 12:58 PM UTC

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;
        }

Translate
ErnIvanAuthor
Known Participant
Sep 10, 2009 2:51 PM UTC

Great !!!!!!

yes It is big ...but  WORKS

many Thanksssss

Translate