顺便说一句,新年快乐!
我想将事件处理与容器及其子项分开。如您所见,我的源代码非常简单:
package {
import flash.display.Sprite;
import flash.display.*;
import flash.events.*;
public class test extends Sprite{
public function test() {
var container:Sprite = new Sprite(); // my container
container.graphics.beginFill(0, 1); // whatever the color
container.graphics.drawRect(0, 0, 100, 100); // origin at 0,0
container.graphics.endFill();
addChild(container);
var decor:Sprite = new Sprite(); // and it child
decor.graphics.beginFill(0, 1); // whatever the color
decor.graphics.drawRect(200, 200, 100, 100); // origin at 200,200
decor.graphics.endFill();
container.addChild(decor);
container.mouseChildren = false;
container.addEventListener(MouseEvent.ROLL_OVER, onOver, false, 0, true);
}
private function onOver(e: MouseEvent):void {
trace("ROLL trace");
}
}
}
当我滚动容器对象时,我得到了跟踪(对我来说很好)。
但是当我滚动装饰对象时,我也得到了痕迹(不是我想要的)。
我只希望容器由鼠标事件触发,而不是它的子事件。
那么我的 mouseChildren = false 怎么了....?我不明白...
最佳答案
decor
对象是 container
的成员,因此它与 container
中的任何其他内容一起被评估.mouseChildren = false;
不是完全禁用鼠标事件的方法,而是降低复合显示对象内的复杂性:鼠标事件仍然被触发,但事件的 target
属性将不包含对鼠标实际滚动的子对象的引用,而仅包含对设置该属性的父对象的引用。
如果你想要 decor
要完全忽略,请使用 decor.mouseEnabled = false;
反而。
关于flash - mouseChildren = false 对我来说效果不佳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8706571/