alien109
asked on
mouseEnabled problem
I've got a sprite with two child sprites. One child sprite has event listeners assigned to it for mouseover/out. the other child sprite is a bitmap which is larger than the sprite with the event listeners. Actually the face that it's a bitmap is irrelevant. Anyway, it's essentially like so:
Parent Sprite "BobsYourUncle"
\--- Child sprite "mouseTarget" (w/event listeners)
\--- Child sprite "evilMouseBlocker" (w/ bitmap object)
Mousing over BobsYourUncle's mouseTarget produces the correct response. However, if another instance of "BobsYourUncle" is placed behind it so that the 1st instance's evilMouseBlocker covers the 2nd instance's mouseTarget, it will not capture the mouseEvent.
I've set the mouseEnabled property of evilMouseBlocker to false, but it does no good. I'm assuming since the second instance is not a parent/child of the 1st instance.
I've set up a quick example of what I'm talking about. See the attached swf.
The nesting of the clips can't change. They mouseTarget and evilMouseBlocker both need to be in a parent container. So how do I disable the mouse for evilMouseBlocker and allow the mouseEvents to be captured in objects outside of the scope of the parent?
Hope that makes sense. Thanks in advance.
example.swf.txt
Parent Sprite "BobsYourUncle"
\--- Child sprite "mouseTarget" (w/event listeners)
\--- Child sprite "evilMouseBlocker" (w/ bitmap object)
Mousing over BobsYourUncle's mouseTarget produces the correct response. However, if another instance of "BobsYourUncle" is placed behind it so that the 1st instance's evilMouseBlocker covers the 2nd instance's mouseTarget, it will not capture the mouseEvent.
I've set the mouseEnabled property of evilMouseBlocker to false, but it does no good. I'm assuming since the second instance is not a parent/child of the 1st instance.
I've set up a quick example of what I'm talking about. See the attached swf.
The nesting of the clips can't change. They mouseTarget and evilMouseBlocker both need to be in a parent container. So how do I disable the mouse for evilMouseBlocker and allow the mouseEvents to be captured in objects outside of the scope of the parent?
Hope that makes sense. Thanks in advance.
example.swf.txt
ur fla will be more useful than the swf.
ASKER
ok got the file - now explain to me in terms of what's suppose to happen and what's not happening?
i.e. with instance 1 and instance 2.
i.e. with instance 1 and instance 2.
Have you also set the mouseChildren = false? make sure you do that
Here's a link if you want more explanation:
http://www.kirupa.com/forum/showthread.php?p=1948039
he mouseChildren property (flash.display.DisplayObje ctContaine r.mouseChi ldren) is a new property that allows you to essentially control the mouseEnabled of all the children of a sprite (or other display object container). This allows the parent sprite to have its own events without having to worry about interference with events coming from its children.
ActionScript Code:
spriteInstance.mouseChildr en = false;
Though ActionScript 3 now has a SimpleButton class (flash.display.SimpleButto n). this property would play an important role in making custom buttons with the MovieClip or Sprite classes. Consider what would happen if you created a rollover event that caused a sprite or movie clip-based button to remove its current graphics and create new ones for a rollover state. With the children of that sprite capable of receiving mouse events, events would fire for the children within the button - events which would propagate to the main sprite. This could mean duplicate events as well as making the event target for those events the children of the button instead of the button itself. Setting mouseChildren to false you can prevent that from happening.
The easiest demonstration is a simple click of a sprite containing another sprite. Change the value of mouseChildren between true and false and notice which sprite is designated as the target of the event:
ActionScript Code:
// main button
var spriteButton:Sprite = new Sprite();
spriteButton.name = "spriteButton";
spriteButton.mouseChildren = true;
// graphics
var spriteGraphics:Sprite = new Sprite();
spriteGraphics.name = "spriteGraphics";
spriteGraphics.graphics.be ginFill(0x 4080A0);
spriteGraphics.graphics.dr awCircle(5 0, 50, 25);
// add to display list
spriteButton.addChild(spri teGraphics );
addChild(spriteButton);
// events
spriteButton.addEventListe ner(MouseE vent.CLICK , click);
function click(evt:MouseEvent):void {
trace(evt.target.name);
}
When true (default), the sprite within the button that was clicked is marked as the target. When false, the button sprite itself is the target - something which is more desirable in this case.
mouseChildren = true; output
Code:
spriteButton
mouseChildren = false; output
Code:
spriteGraphics
http://www.kirupa.com/forum/showthread.php?p=1948039
he mouseChildren property (flash.display.DisplayObje
ActionScript Code:
spriteInstance.mouseChildr
Though ActionScript 3 now has a SimpleButton class (flash.display.SimpleButto
The easiest demonstration is a simple click of a sprite containing another sprite. Change the value of mouseChildren between true and false and notice which sprite is designated as the target of the event:
ActionScript Code:
// main button
var spriteButton:Sprite = new Sprite();
spriteButton.name = "spriteButton";
spriteButton.mouseChildren
// graphics
var spriteGraphics:Sprite = new Sprite();
spriteGraphics.name = "spriteGraphics";
spriteGraphics.graphics.be
spriteGraphics.graphics.dr
// add to display list
spriteButton.addChild(spri
addChild(spriteButton);
// events
spriteButton.addEventListe
function click(evt:MouseEvent):void
trace(evt.target.name);
}
When true (default), the sprite within the button that was clicked is marked as the target. When false, the button sprite itself is the target - something which is more desirable in this case.
mouseChildren = true; output
Code:
spriteButton
mouseChildren = false; output
Code:
spriteGraphics
ASKER
The desired result would be that instance1's mouseBlocker would not prevent instance2's mouseTarget from capturing the roll_over event. Essentially, mouseBlocker doesn't block anything. Maybe a bad name for my example...
If I set mouseEnabled to false for the mouseBlocker, it works, but only for its siblings. I need it to work for anything, regardless of relationship.
If I set mouseEnabled to false for the mouseBlocker, it works, but only for its siblings. I need it to work for anything, regardless of relationship.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I can't set mouseChildren to false on the parent sprite. that will prevent the child sprite that is handling the events to not work.
This might be a no-can-do sorta thing and need to restructure things...
This might be a no-can-do sorta thing and need to restructure things...
It's starting to smell that way....
ASKER
k. i was being dumb...
if I set mouseEnabled to false on the parent and the mouseBlocker and mouseEnabled to true on the mouseTarget, it works how I was hoping.
Thanks for the help nonetheless.
if I set mouseEnabled to false on the parent and the mouseBlocker and mouseEnabled to true on the mouseTarget, it works how I was hoping.
Thanks for the help nonetheless.
tomaugerdotcom offered the assistance to resolving the problem no?
i'm objecting on tomaugerdotcom's behalf, but if he has no objections then I guess you can go ahead and do what you feel is right.
Thanks BG. Much appreciated!
I"m not desperate for points, but I do feel that I provided the OP with a bunch of relevant information which I'm presuming helped arrive at the resolution of the issue. I'll leave it up to the OP to decide what is fair here.
I"m not desperate for points, but I do feel that I provided the OP with a bunch of relevant information which I'm presuming helped arrive at the resolution of the issue. I'll leave it up to the OP to decide what is fair here.
ASKER
Sorry for the delay - out of town on business...
it was sorta self deduced, but i have no problem with awarding the points. Sorry about that. And thank you both for the help and replies.
it was sorta self deduced, but i have no problem with awarding the points. Sorry about that. And thank you both for the help and replies.
Mucho appreciado!
T
T