Solved

mouseEnabled problem

Posted on 2009-04-02
16
2,254 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
  • 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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 500 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
IE 11 Flash Player issue 7 245
Where to download Adobe Flash Player 11.9.900.170 5 1,365
Array is not working ( AS2 ) 4 158
Software Restriction Policy 8 874
I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

821 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