Hi,
this post is based on senoculars http://www.kirupa.com/forum/showthread.php?p=1948182
post. btw very enlighting post although I still have a problem:diss:
OK the objective is to have a display object and to disallow clicking anywhere on the stage apart from that display object. Once back on the display object all other objects on the stage should be again active. (the display object is a window component that can be closed thats why I need to have all the other objects on the stage active).
I tried this code:
// create a circle to click
var circle:Sprite = new Sprite();
circle.graphics.beginFill(0x4080A0);
circle.graphics.drawCircle(50, 50, 25);
addChild(circle);
circle.addEventListener(MouseEvent.MOUSE_OUT, mouseOut);
//circle.addEventListener(MouseEvent.MOUSE_OVER, mouseOverC);
function mouseOut(event:MouseEvent):void {
// down, now check for global mouseUp
trace("circle mouseOut");
stage.addEventListener(MouseEvent.MOUSE_OVER, mouseOver, true);
}
function mouseOver(event:MouseEvent):void {
trace("mouseOver");
if (event.target == circle){
// mouse is up over circle (onRelease)
// (if circle is not a DisplayObjectContainer,
// you do not need to use the contains check)
trace(event.target)
} else {
// mouse is up outside circle (onReleaseOutside)
if(event.eventPhase == EventPhase.CAPTURING_PHASE) {
trace("capturing");
trace("event.target.name: "+event.target.name);
trace("currentTarget: "+event.currentTarget);
event.target.mouseEnabled = false;
}
var temp:Object = event.target;
temp.addEventListener(MouseEvent.MOUSE_OVER, mouseOver2);
}
// be sure to clean up stage listener
stage.removeEventListener(MouseEvent.MOUSE_OVER, mouseOver, true);
}
function mouseOver2(event:MouseEvent):void{
trace("mouseOver2: "+event.target.name);
event.target.mouseEnabled = true;
}
Now the problem I think is that I set mouseEnabled=false while the event is on the EVENT_CAPTURING phase. So by the time its in the AT_TARGET phase the mouseOver2 listener kicks in and reactivates the mouseEnabled property.
I tried various things and obviously I’m missing something basic here so sorry if this post is kind of duplicate…
Obviously the solution of having a rectangle covering the stage once the mouse is out of the display object to prevent clicking anywhere else works but I thought trying a different approach:)
thanks
stelios