顺便说一句,新年快乐!
我想将事件处理与容器及其子项分开。如您所见,我的源代码非常简单:
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 怎么了……?我不明白...