Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

mouseEnabled problem

Posted on 2009-04-02
16
Medium Priority
?
2,284 Views
Last Modified: 2013-11-11
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
Comment
Question by:alien109
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 4
16 Comments
 
LVL 39

Expert Comment

by:blue-genie
ID: 24057123
ur fla will be more useful than the swf.
0
 
LVL 12

Author Comment

by:alien109
ID: 24057192
Sure, although this is just an example of the situation.

Thanks man.
example.fla.txt
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 24057896
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:tomaugerdotcom
ID: 24059659
Have you also set the mouseChildren = false? make sure you do that
0
 
LVL 14

Expert Comment

by:tomaugerdotcom
ID: 24059681
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
 
LVL 12

Author Comment

by:alien109
ID: 24059708
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
 
LVL 14

Accepted Solution

by:
tomaugerdotcom earned 2000 total points
ID: 24059973
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
 
LVL 12

Author Comment

by:alien109
ID: 24062801
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
 
LVL 14

Expert Comment

by:tomaugerdotcom
ID: 24063360
It's starting to smell that way....
0
 
LVL 12

Author Comment

by:alien109
ID: 24066120
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
 
LVL 39

Expert Comment

by:blue-genie
ID: 24076508
tomaugerdotcom offered the assistance to resolving the problem no?
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 24084226
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
 
LVL 14

Expert Comment

by:tomaugerdotcom
ID: 24091401
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
 
LVL 12

Author Comment

by:alien109
ID: 24092977
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
 
LVL 14

Expert Comment

by:tomaugerdotcom
ID: 24096669
Mucho appreciado!

T
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question