FLEX:How to catch 'a href' event

前端 未结 3 691
南旧
南旧 2021-01-25 09:56

I\'m loading data from TextFlow to spark:TextArea. In TextFlow i have \'a href\' elements. Problem lies with the address of the \'link\' elements. Some of them will go outside o

相关标签:
3条回答
  • 2021-01-25 09:56

    Maybe this helps. I use a html-link like this:

    <a id="link_1"> Click me </a>
    

    The html-file is stored externally. I import the html to a TextFlow using importToFlow and add the Listener in Flex, like this:

    myTextFlow.addEventListener(FlowElementMouseEvent.ROLL_OVER, showMe);
    

    To get the id-property of the link I use:

    event.flowElement.id
    
    0 讨论(0)
  • 2021-01-25 10:02

    OK i found answer on this blog: http://flexdevtips.blogspot.com/2010/10/displaying-html-text-in-labels.html

    Bassicly i had to search whole textFlow and in case of founding a Link - adding manually Event to it.

    Im posting my code in case that the flexdevtips blog might be down in the future:

    /**
    * Finds the first LinkElement recursively and returns it.
    */          
    
    private function findLinkElement(group:FlowGroupElement):void
    {
        var childGroups:Array = [];
        // First check all the child elements of the current group,
        // Also save any children that are FlowGroupElement
        for (var i:int = 0; i < group.numChildren; i++) {
            var element:FlowElement = group.getChildAt(i);
            if (element is LinkElement) 
            {
                linksArray.push(element as LinkElement);
            } else if (element is FlowGroupElement)
            {
                childGroups.push(element);
            }
        }
        // Recursively check the child FlowGroupElements now
        for (i = 0; i < childGroups.length; i++) {
            var childGroup:FlowGroupElement = childGroups[i];
            findLinkElement(childGroup);
        }
    
      }
    

    and i had to use it in my code like this:

    linksArray = [];
    
    findLinkElement(tt.textFlow);
    
    var iter:int=0;
    for (iter = 0 ; iter<linksArray.length ; iter++)
    {
                    linksArray[iter].addEventListener(FlowElementMouseEvent.MOUSE_DOWN,linkSelect, false, 0, true);
    }
    

    where tt is my textarea with imported textFlow

    0 讨论(0)
  • 2021-01-25 10:04

    just found out how to get the original string:

    function onClick(event:FlowElementMouseEvent):void 
    {
        var link:LinkElement = event.flowElement as LinkElement;
        var text:String = link.href;
    }
    

    this will return the content of the tag, so you can parse to get your parameters

    thanks for the post, it helped me a lot. at least i got one step further, i can actually listen to the events.

    but i still have a problem, the HTML code i set on my RichEditableText looks like this:

    <a href='event:n," + id + "'>Name</a>
    

    on Flex3 i could use the TextEvent.LINK get the arguments by its 'text' property, then parse to get the ID data that i need. but now that we are developing in Flex4 i cannot figure out how to do this. after catching the FlowElementMouseEvent i can only get the link text ('Name'), but not the arguments im sending on the HTML code.

    do you have any suggestions on how to do this?

    0 讨论(0)
提交回复
热议问题