Can match with each other exclude the event?

Below is the code for a simple ActionScript Flex project. The sprite partially covers the hyperlink. What happens when you hover over a sprite, if you also hover over a hyperlink, the hyperlink is activated. I want to prevent this. I only want the hyperlink to activate when the mouse hovers over it - not when the mouse hovers over the sprite that covers it.

package {

import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.TextEvent;
import flash.text.Font;
import flash.text.StyleSheet;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;


public class SpriteHyperlinkTest extends Sprite
{
    private var style : StyleSheet = new StyleSheet();
    public function SpriteHyperlinkTest()
    {
            createOutputTextField();
    }

    public var output_txt : TextField;

    private function createOutputTextField() : void {

            // set styles
            var hover : Object = new Object();
            hover.fontWeight = "bold";
            hover.color = "#0000FF";
            var link : Object = new Object();
            link.fontWeight = "bold";
            link.textDecoration = "underline";
            link.color = "#555555";
            var active : Object = new Object();
            active.fontWeight = "bold";
            active.color = "#FF0000";

            var visited : Object = new Object();
            visited.fontWeight = "bold";
            visited.color = "#cc0099";
            visited.textDecoration = "underline";

            style.setStyle("a:link", link);
            style.setStyle("a:hover", hover);
            style.setStyle("a:active", active);
            style.setStyle(".visited", visited);
            output_txt = new TextField();
            output_txt.backgroundColor = 0xFFFFFF;
            output_txt.background = true;
            //output_txt.embedFonts = true;
            output_txt.wordWrap = true;
            output_txt.multiline = true;

            output_txt.name = "output_txt";                 
            output_txt.x = 100;
            output_txt.y = 100;
            output_txt.width = 300;
            output_txt.height = 200;

            output_txt.htmlText = "<b>sample <a href='http://www.google.com'>hyperlink text</a></b>"; 
            addChild(output_txt);

     var mySprite:Sprite = new Sprite();
             mySprite.graphics.lineStyle(.5,0x000000);
     mySprite.graphics.beginFill(0xff0000, 1);
     mySprite.alpha = .7;
     mySprite.graphics.drawRect(100, 100, 90, 20);
     mySprite.graphics.endFill();
     mySprite.useHandCursor = true;
     mySprite.mouseChildren = true;
     mySprite.buttonMode = true;
     mySprite.name = "Sprite1";
     this.addChild(mySprite);

     output_txt.styleSheet = style;
    }

  }
}

      

+2


source to share


3 answers


I almost found a workaround. It's just amazing that there isn't some kind of object that can be placed on top of the text box so that it doesn't see the mouse traverse the hyperlink.

Here, for the record, are some of the things I've tried.

stopPropagation () // doesn't work stopImmediatePropagation (P // doesn't work

Since the textbox and sprite are siblings in the display list, I think all of the event propagation stuff is irrelevant. All of this is related to ancestors and descendants, but what we are dealing with is neither the one nor the other.



I tried to place another textbox ("skin") on top of the "target" textbox. I tried to set cover.visible = false; but that just meant it wasn't effective. I tried setting its .1 alpha file, but that didn't work either - just like the sprite sprite, it let mouseOver go through it for the hyperlink to react.

I was thinking about trying to use preventDefault () on the hyperlink, but a) I don't know how to reference the hyperlink (it has no ID), and b) the only event dispatched from the hyperlink is the TextEvent, and that's when it clicked. We do not click, we soar. So I don't know which event to cancel.

Another thing I thought was a fake "undo". That is, perhaps I could set the textformat or hyperlink style to look like normal text while the mouse hovers over the sprite. The hyperlink will actually be activated, but it will look like it will not be activated because the style will be changed. This is what worked.

But this is just a fake visual workaround ...

+1


source


I'll add rollOver (or whatever event you're trying to block) an event listener for the sprite on top of the hyperlink. In your rollover handler, make sure to call event.stopImmediatePropagation () and this should prevent the hyperlink at the bottom from receiving the event.



0


source


I've never seen this behavior before. Your code example doesn't even assign events. I would be interested to know how you are assigning events, because that in itself could be the cause of your problem.

0


source







All Articles