simPod
simPod

Reputation: 13456

All children disabled, only one mouse active

I have a Movieclip (instance: my_mc) that holds Sprite, Bitmap, Texfield and Button (children)

The Movieclip (my_mc) has some variables I want to access from my event through e.target

my_mc.addEventListener(MouseEvent.CLICK, my_fc);
function my_fc(e:MouseEvent):void{
    ...
}

so when someone clicks on a object that is a child of my_mc, only my_mc actually receives the CLICK

for this purpose I used my_mc.mouseChildren = false;

BUT I also need to have button still active so that would be only child that also receives the CLICK when someone clicks it. I have tried to add button.mouseEnabled = true; but that doesn't work...

Any suggestions?

Upvotes: 2

Views: 6456

Answers (2)

Daniel
Daniel

Reputation: 35684

cauko, skus toto....

This is assuming that your button is called btn, if there are more you might need to assign the 2ndary listener dynamically. You cannot use my_mc.mouseChildren = false; because that removes all mouse events.

my_mc.addEventListener(MouseEvent.CLICK, my_fc);
function my_fc(e:MouseEvent):void{
    doSomething(e.target as MovieClip)
}
my_mc.btn.addEventListener(MouseEvent.CLICK, my_fc2);
function my_fc2(e:MouseEvent):void{
    e.stopImmediatePropagation();
    doSomething(e.target.parent);
}
function doSomething(mc:MovieClip):void{
    trace(mc);
}

Upvotes: 1

SimplyZ
SimplyZ

Reputation: 908

If the button is inside of my_mc then you need to use my_mc.button.mouseEnabled = true;

and be sure to have an event listener for my_mc.button aswell: my_mc.button.addEventListener(MouseEvent.CLICK, buttonHandler);

and a buttonHandler function aswell.

And if it still doesn't work....

Separate the buttons into a different movieclip and position them to where you want them to be. Then just simply use my_mc.mouseChildren = false; on your original movieclip and not on the buttons.

Upvotes: 2

Related Questions