Disabling Event listener for child sprite

Hello I have a main sprite that contains contains 5 buttons sprites.

I have registered a event listener with the main sprite

mainSprite.addEventListener(MouseEvent.CLICK, on Click);

function onClick(e:MouseEvent):void
{
trace(e.target.name);
}

I want to prevent the button that is clicked from receiving CLICK event again how can I do that?

Thanks in advance

mainSprite.mouseChildren = false;

Hi

Thanks for the reply.

But this will disable the all the children I just want to disable the one that is being clicked. I hope I am making sense.

By the way I checked your website very nice work.

You could either store its name in an array (target.name) and do a conditional when it’s clicked again, or you could just setup individual listeners for each button.

The latter sounds better to me :slight_smile:

And thanks, btw, appreciate the kind words.

Hello

Thanks again

Yes I can do a conditional to check whether it was clicked before or not you said that the other option souds better.

I am not a hard coder like you I am trying to write efficient code can you please tell me which approach is better because If I assign individual listeners to each button and lets suppose I have 50 buttons then wont it be inefficient?

One more thing can you please tell me that whether you have made your website in AS2 or AS3 and what design programme you use to design your backgrouds and art? Thanks

I like the idea of 50 listeners better than conditionals tbh, just for code clarity. They can all use the same callback as well, so you can just loop the listeners out.

something like this (warning, browser code :P)

`
for (var i:int = 0; i < numButtons; i++) {
_buttonArray*.addEventListener(MouseEvent.CLICK, myCallback);
};

function myCallback(e:MouseEvent):void {
e.currentTarget.removeEventListener(MouseEvent.CLICK, myCallback);
};
`

My website has a few years on it, and it was made in AS2. As for design programs, there’s really no art going on there :stuck_out_tongue: it’s just a few gradients and fonts :wink: