Note that there are some explanatory texts on larger screens.

plurals
  1. POActionscript Mouse Events to multiple items
    text
    copied!<p>Ok, so for my problem, and specific times where it occurs, I have a DisplayObject at the bottom, that's clickable and has a hover state, underneath a TextField. The big problem is, I need all MouseEvents to go to <em>both</em> of them, not just the TextField, not just the DisplayObject. Reason being is I have text that require tooltips to be attached to the mouse which are on top of those DisplayObjects underneath.</p> <pre><code>package { import flash.display.InteractiveObject; import flash.display.Sprite; import flash.events.MouseEvent; import flash.geom.ColorTransform; import flash.text.TextField; [SWF(width="400", height="400", frameRate="24", backgroundColor="#EEEEEE")] public class tester2 extends Sprite { protected var cTransform:ColorTransform; protected var rect:Sprite; protected const RECT_ON_COLOUR:uint = 0xFF0000; protected const RECT_OFF_COLOUR:uint = 0x0000FF; protected var text:TextField; protected const TEXT_ON_COLOUR:uint = 0xFFFFFF; protected const TEXT_OFF_COLOUR:uint = 0x000000; public function tester2() { rect = new Sprite(); rect.graphics.lineStyle(1); rect.graphics.beginFill(RECT_OFF_COLOUR, 0.8); rect.graphics.drawRect(10, 10, 100, 100); rect.graphics.endFill(); add(rect); text = new TextField(); text.text = "TextField"; text.selectable = false; text.height = 30; text.x = text.y = 13; text.textColor = TEXT_OFF_COLOUR; add(text); cTransform = new ColorTransform(); } protected function add(item:InteractiveObject):void { addChild(item); item.addEventListener(MouseEvent.MOUSE_MOVE, onMouseEvent); item.addEventListener(MouseEvent.MOUSE_OUT, onMouseEvent); } protected function onMouseEvent(e:MouseEvent):void { setColour(e.target, (e.type == MouseEvent.MOUSE_MOVE)); } protected function setColour(item:Object, over:Boolean):void { if(item == rect) { cTransform.color = (over? RECT_ON_COLOUR: RECT_OFF_COLOUR); rect.transform.colorTransform = cTransform; } else { text.textColor = (over? TEXT_ON_COLOUR: TEXT_OFF_COLOUR); } } } } </code></pre> <p>You can see the affect of the above example here, <a href="http://seadersforums.appspot.com/static/4stack/multiple_mouse_events/index.html" rel="nofollow">http://seadersforums.appspot.com/static/4stack/multiple_mouse_events/index.html</a></p> <p>Now, what I want to force happen is when you mouse over any of the text area, the text to pick up that event, as well as any other mouse event, as well as the DisplayObject underneath. To put it one way, I want to have my cake, and eat it too. I want the text to act the way it is in this example, but also to have it work as if I had mouseEnabled equal to false on the text.</p> <p>I asked a similar question previously about Bitmaps, albeit in different circumstances and eventually went with a parent.getObjectsUnderPoint... solution, which was less than ideal. If that's my only option here... I'll begrudgingly go that way again, but I'd love to find a better solution and really do think there must be, insofar as I could just clone the event down the line to the next child at that point.</p> <p>Thanks for any help you can give.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload