I make a sprite, then add a child sprite.
I add a listener to the child for MOUSE_OUT events.
If my mouse is in the child sprite when I set the parent sprite mouseEnabled=false and mouseChildren=false, MOUSE_OUT is not fired on the child.
But then, when I move the mouse, MOUSE_OUT is fired on the child. MOUSE_OUT is also fired if I click. MOUSE_OUT is not fired if I mousewheel.
So, what's going on here?
This is a related question.
After studying back2dos' code, I discovered what I am doing differently is calling stage.focus = null just before setting mouseChildren = mouseEnabled = false. I am setting the stage focus to null to clear the blinking cursor from a textfield... is there a better way to do this?
here is back2dos' modified code. steps to reproduce: click the textfield, get the blinking cursor. click the "button", but don't move the mouse between down and up. note the cursor is not blinking (good). also note that the mouse_out events on the button have not fired. until you move or click the mouse.
package {
import flash.display.*;
import flash.events.*;
import flash.geom.ColorTransform;
public class Test extends Sprite {
private var child:Sprite
public function Test() {
this.addChild(child = new Sprite());
child.graphics.beginFill(0xFF0000);
child.graphics.drawRect(0, 0, 100, 20);
child.addEventListener(MouseEvent.CLICK, onClick);
child.addEventListener(MouseEvent.MOUSE_OUT, onOut);
child.addEventListener(MouseEvent.MOUSE_OVER, onOver);
tf = new TextField( );
tf.backgroundColor = 0xFF00AA;
tf.background = true;
tf.type = TextFieldType.INPUT;
tf.text = "yo";
tf.y = 100;
this.addChild( tf );
}
private function onOver(e:MouseEvent):void {
child.transform.colorTransform = new ColorTransform(0, 0, 0, 1, 0, 0xFF);
}
private function onOut(e:MouseEvent):void {
child.transform.colorTransform = new ColorTransform();
}
private function onClick(e:MouseEvent):void {
//try it here...
stage.focus = null;
this.mouseChildren = this.mouseEnabled = false;
//or try it here...
//stage.focus = null;
}
}
}