QuickTip: Stopping an Event
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.
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:
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 ;)
- QuickTip: Execute Code After Animaiton
- QuickTip: Scrolling Only in SWF, not on Page.
- QuickTip: Managing Saved Data (SharedObject)
- QuickTip: Understanding Right Click Menus (ContextMenu)
- QuickTip: Stopping an Event
- QuickTip: Avoid Firefox popup-blocker When Using navigateToUrl
- QuickTip: Inline If-Then-Else Statement
- QucikTip: Trace an Array With Correct Formatting
Posted on May 3rd, 2010 Filed under ActionScript 3, Flash, Tutorial, User Interface |
VERY VERY VERY VERY VERY VERY USEFUL!!!! THANKS!