A link inside TextFlow: rollOver/rollOut bubbles, shouldn't bubble, and cannot be avoided

641 Views Asked by At

I'm having a weird behavior. I have an HTML link inside a TextFlow. When I set its linkHoverFormat, it starts sending rollOver/rollOut events up the chain. These events say the don't bubble but somehow they do. And I can't seem to stop them from doing so.

Here's an example:

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                       xmlns:s="library://ns.adobe.com/flex/spark" 
                       xmlns:mx="library://ns.adobe.com/flex/mx">

  <fx:Declarations>
    <s:TextLayoutFormat id="linkNormal" textDecoration="none" color="0x556677"/>  
    <s:TextLayoutFormat id="linkHover" textDecoration="underline" color="0x0000FF"/>
    <s:TextFlow id="textFlow1" 
                linkActiveFormat="{linkHover}" 
                linkHoverFormat="{linkHover}"
                linkNormalFormat="{linkNormal}">
      <s:p> <s:a href="http://projects.nunogodinho.com">hover</s:a> </s:p>
    </s:TextFlow>
  </fx:Declarations>

  <fx:Script>
    <![CDATA[

      // This pair of handlers is triggered by the panel
      protected function rollOverHandler(e:MouseEvent):void {
        panel.title = "over";
      }
      protected function rollOutHandler(e:MouseEvent):void {
        panel.title = "out";
      }

    ]]>
  </fx:Script>

  <s:Panel left="10" top="10" id="panel" mouseOver="rollOverHandler(event)" mouseOut="rollOutHandler(event)">
    <s:RichEditableText id="ret1"
                        top="10"
                        editable="false"
                        textFlow="{textFlow1}" />
  </s:Panel>

</s:WindowedApplication>

If you run this app and move the mouse over the link several times without moving out of the panel you'll see that it still changes the text.

So I decided to try to stop this strange event from bubbling:

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                       xmlns:s="library://ns.adobe.com/flex/spark" 
                       xmlns:mx="library://ns.adobe.com/flex/mx">

  <fx:Declarations>
    <s:TextLayoutFormat id="linkNormal" textDecoration="none" color="0x556677"/>  
    <s:TextLayoutFormat id="linkHover" textDecoration="underline" color="0x0000FF"/>
    <s:TextFlow id="textFlow2" 
                linkActiveFormat="{linkHover}" 
                linkHoverFormat="{linkHover}"
                linkNormalFormat="{linkNormal}">
      <s:p> <s:a rollOver="linkelement2_rollOverHandler(event)" rollOut="linkelement2_rollOutHandler(event)" href="http://projects.nunogodinho.com">hover</s:a> </s:p>
    </s:TextFlow>
  </fx:Declarations>

  <fx:Script>
    <![CDATA[
      import flashx.textLayout.events.FlowElementMouseEvent;

      // This pair of handlers is triggered by the panel
      protected function rollOverHandler(e:MouseEvent):void {
        panel.title = "over";
      }
      protected function rollOutHandler(e:MouseEvent):void {
        panel.title = "out";
      }

      // This pair of handlers is triggered by the <A> element inside textFlow2
      // and I hoped it would stop the event from bubbling up to the panel
      protected function linkelement2_rollOverHandler(e:FlowElementMouseEvent):void {
        e.preventDefault();
        e.stopImmediatePropagation();
        e.stopPropagation()
      }
      protected function linkelement2_rollOutHandler(e:FlowElementMouseEvent):void {
        e.preventDefault();
        e.stopImmediatePropagation();
        e.stopPropagation()
      }

      // I also tried to intercept the event in the RichEditableText but got the same weird
      // behavior: the event triggers the panel's rollOver/rollOut intermittently


    ]]>
  </fx:Script>

  <s:Panel left="10" top="10" id="panel" mouseOver="rollOverHandler(event)" mouseOut="rollOutHandler(event)">
    <s:RichEditableText top="10" left="55"
                        editable="false"
                        textFlow="{textFlow2}" />
  </s:Panel>

</s:WindowedApplication>

I tried all combinations of preventDefault, stopImmediatePropagation and stopPropagation. It does change the event's behavior but it also ruins the hovering effect on the link.

Then I tried to intercept the event at the RichEditableText but I got the same kind of results.

Once I had a similar problem but I learned that it was because I was using mouseOver/mouseOut events instead of rollOver/rollOut. Since I switched to rollOver/rollOut it worked fine. Until now.

And now I'm clueless.

Please help.

Thanks.

0

There are 0 best solutions below