QuickTip: Stopping an Event

This entry is part of a series, Quick Tips»

Learn how to stop an event, and also why.

I play a lot of games that makes a mistake in the UI, and it’s so freaking simple to correct. What mistake am I talking about? Well I just made a little sample of it, picture this is a shooting game (and I guess you need to use a lot of your imagination there), and we have a button for changing the sound. Try clicking on the “empty” space of the swf, and on the sound button.

(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

What do you see? Oh yes, when we try and turn off the sound, we also shoot! That’s not good, I didn’t want to waste my precious ammo, I just wanted to turn the sound off.

 

And here is how to fix it:

In the event handler for the sound button, just add this line of code:

e.stopPropagation ( ) ;

Here is the result:
(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

Hurray, problem solved!

 

Want to learn a little about what you just did, or more generally how events work? Take a look at this great article from Adobe.

 

Happy coding ;)

Posted on May 3rd, 2010
Filed under ActionScript 3, Flash, Tutorial, User Interface |

One Response to “QuickTip: Stopping an Event”

  1. MC
    September 1st, 2010 at 13:36

    VERY VERY VERY VERY VERY VERY USEFUL!!!! THANKS!

Leave a Reply