Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2300
  • Last Modified:

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
0
alien109
Asked:
alien109
  • 6
  • 5
  • 4
1 Solution
 
blue-genieCommented:
ur fla will be more useful than the swf.
0
 
alien109Author Commented:
Sure, although this is just an example of the situation.

Thanks man.
example.fla.txt
0
 
blue-genieCommented:
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.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
tomaugerdotcomCommented:
Have you also set the mouseChildren = false? make sure you do that
0
 
tomaugerdotcomCommented:
Here's a link if you want more explanation:
http://www.kirupa.com/forum/showthread.php?p=1948039

he mouseChildren property (flash.display.DisplayObjectContainer.mouseChildren) 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.mouseChildren = false;



Though ActionScript 3 now has a SimpleButton class (flash.display.SimpleButton). 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.beginFill(0x4080A0);
spriteGraphics.graphics.drawCircle(50, 50, 25);

// add to display list
spriteButton.addChild(spriteGraphics);
addChild(spriteButton);

// events
spriteButton.addEventListener(MouseEvent.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

0
 
alien109Author Commented:
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.
0
 
tomaugerdotcomCommented:
Is mouseBlocker a MC with embedded MCs? If that's the case, mouseChildren=false is required. If not, then there's a structural problem that mouseChildren alone cannot solve. Look at your event bubbling and see if you can capture your rollovers another way - look up "hitTestPoint()" where you would pass the mouse x and y coords as a Point to the function. This would go inside a mouseMoved event handler on the Stage.

T
0
 
alien109Author Commented:
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...
0
 
tomaugerdotcomCommented:
It's starting to smell that way....
0
 
alien109Author Commented:
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.
0
 
blue-genieCommented:
tomaugerdotcom offered the assistance to resolving the problem no?
0
 
blue-genieCommented:
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.
0
 
tomaugerdotcomCommented:
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.
0
 
alien109Author Commented:
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.
0
 
tomaugerdotcomCommented:
Mucho appreciado!

T
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 6
  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now