【发布时间】:2011-05-13 12:03:54
【问题描述】:
好的,所以对于我的问题,以及它发生的特定时间,我在底部有一个 DisplayObject,它是可点击的,并且具有悬停状态,位于 TextField 下方。最大的问题是,我需要所有的 MouseEvents 都去 both,而不仅仅是 TextField,而不仅仅是 DisplayObject。原因是我有文本需要将工具提示附加到位于下方那些 DisplayObjects 之上的鼠标。
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);
}
}
}
}
你可以在这里看到上面例子的效果, http://seadersforums.appspot.com/static/4stack/multiple_mouse_events/index.html
现在,我想要强制发生的是,当您将鼠标悬停在任何文本区域上时,要拾取该事件的文本,以及任何其他鼠标事件,以及下方的 DisplayObject。换句话说,我想吃蛋糕,也想吃。我希望文本按照本示例中的方式运行,但也让它像我在文本上的 mouseEnabled 等于 false 一样工作。
我之前问过一个关于位图的类似问题,尽管在不同的情况下,最终选择了 parent.getObjectsUnderPoint... 解决方案,这不太理想。如果这是我在这里唯一的选择......我会不情愿地再次这样做,但我很想找到一个更好的解决方案并且真的认为必须有,只要我可以将事件克隆到下一个那个时候的孩子。
感谢您提供的任何帮助。
【问题讨论】:
标签: flash actionscript mouseevent