intercept all buttons clicks
My question is:
Is there a way that I can intercept all button click event in my Flex(air) app, because I need to add a sound when some button is clicked, and I dont want go over all screens and add this function and also change each click event in each button.
So is there a way that I 开发者_如何转开发can do this?
Thanks!
It depends on your specific site structure how easy it might be to do this. Do your buttons all have their own unique Class, or otherwise share some distinguishing feature (a common hungarian style _btn marker in their instance names)? If so, you could try something like this:
root.addEventListener(MouseEvent.CLICK, onButtonClickPlaySound);
private function onButtonClickPlaySound(e:MouseEvent):void{
if(e.target is ExtendedButton){
// play sound here...
}
// or....
if(e.target.name.indexOf("hungariannotation") >= 0){
// play sound here...
}
}
This won't work if handlers down the display list stop event propagation. The mouse clicks must bubble all the way to the root.
精彩评论