logo
g Text Version
Beauty & Self
Books & Music
Career
Computers
Education
Family
Food & Wine
Health & Fitness
Hobbies & Crafts
Home & Garden
Money
News & Politics
Relationships
Religion & Spirituality
Sports
Travel & Culture
TV & Movies

dailyclick
Bored? Games!
Nutrition
Postcards
Take a Quiz
Rate My Photo

new
Action Movies
Bible Basics
Houseplants
Romance Movies
Creativity
Family Travel
Southwest USA


dailyclick
All times in EST

Full Schedule
g
g Flash and Animation Site

BellaOnline's Flash and Animation Editor

g

Toggle Buttons and Event Listeners


As we mentioned earlier, when creating FlashR apps for mobile devices, it's very important to remove event listeners as soon as they are no longer needed. In this tutorial, we will code two functions that will run when the Menu Overlay is moved on or off the stage. We will call these functions loadListeners and removeListeners.

So what will these functions do when the Menu Overlay is moved? First, let's discuss what will happen with we click the toggle button to remove the menu from the stage, which is the removeListeners() function.

For each button or hyperlink on the menu, we will want to turn everything off. For example, we will set the buttonMode and useHandCursor properties to false. Also, we don't want Flash to be listening for the button click events associated with these menu buttons when the menu is not on the stage. So we will remove the event listeners from these buttons. The example below is for the website button.

websiteBtn.buttonMode = false;
websiteBtn.useHandCursor = false;
websiteBtn.removeEventListener(MouseEvent.CLICK, goWebsite);

When the menu is toggled back onto the stage we run the loadListeners function which set the buttonMode and useHandCursor properties back to true and add event listeners to each button on the menu. For the websiteBtn we will do this.

websiteBtn.buttonMode = true;
websiteBtn.useHandCursor = true;
websiteBtn.addEventListener(MouseEvent.CLICK, goWebsite, false, 0, true);

Here is the complete code.

function removeListeners():void {

websiteBtn.buttonMode = false;
websiteBtn.useHandCursor = false;
moreAppsBtn.buttonMode = false;
moreAppsBtn.useHandCursor = false;
creditsBtn.buttonMode = false;
creditsBtn.useHandCursor = false;
indexBtn.buttonMode = false;
indexBtn.useHandCursor = false;
musicBtn.buttonMode = false;
musicBtn.useHandCursor = false;

websiteBtn.removeEventListener(MouseEvent.CLICK, goWebsite);
moreAppsBtn.removeEventListener(MouseEvent.CLICK, goMoreApps);
creditsBtn.removeEventListener(MouseEvent.CLICK, goCredits);
indexBtn.removeEventListener(MouseEvent.CLICK, goIndex);
musicBtn.removeEventListener(MouseEvent.CLICK, stopMusic);

}

function loadListeners():void {

websiteBtn.buttonMode = true;
websiteBtn.useHandCursor = true;
moreAppsBtn.buttonMode = true;
moreAppsBtn.useHandCursor = true;
creditsBtn.buttonMode = true;
creditsBtn.useHandCursor = true;
indexBtn.buttonMode = true;
indexBtn.useHandCursor = true;
musicBtn.buttonMode = true;
musicBtn.useHandCursor = true;

websiteBtn.addEventListener(MouseEvent.CLICK, goWebsite, false, 0, true);
moreAppsBtn.addEventListener(MouseEvent.CLICK, goMoreApps, false, 0, true);
creditsBtn.addEventListener(MouseEvent.CLICK, goCredits, false, 0, true);
indexBtn.addEventListener(MouseEvent.CLICK, goIndex, false, 0, true);
musicBtn.addEventListener(MouseEvent.CLICK, stopMusic, false, 0, true);

}

← Back


Join us in the Flash forum. | Join us in the Digital Art and Design forum.

|


Add Toggle+Buttons+and+Event+Listeners to Twitter Add Toggle+Buttons+and+Event+Listeners to Facebook Add Toggle+Buttons+and+Event+Listeners to MySpace Add Toggle+Buttons+and+Event+Listeners to Del.icio.us Digg Toggle+Buttons+and+Event+Listeners Add Toggle+Buttons+and+Event+Listeners to Yahoo My Web Add Toggle+Buttons+and+Event+Listeners to Google Bookmarks Add Toggle+Buttons+and+Event+Listeners to Stumbleupon Add Toggle+Buttons+and+Event+Listeners to Reddit



 



RSS | Related Articles | Editor's Picks Articles | Top Ten Articles | Previous Features | Site Map


For FREE email updates, subscribe to the Flash and Animation Newsletter


Past Issues


print
Printer Friendly
bookmark
Bookmark
tell friend
Tell a Friend
forum
Forum
email
Email Editor


Content copyright © 2014 by Diane Cipollo. All rights reserved.
This content was written by Diane Cipollo. If you wish to use this content in any manner, you need written permission. Contact Diane Cipollo for details.

g


g features
Particle System - Emitter Shape Parameters

Motion Particle Systems - Introduction

Particle Fog in Motion 5 - Scene Graphics

Archives | Site Map

forum
Forum
email
Contact

Past Issues
memberscenter


vote
Poetry
Daily
Weekly
Monthly
Less than Monthly



BellaOnline on Facebook
g


| About BellaOnline | Privacy Policy | Advertising | Become an Editor |
Website copyright © 2014 Minerva WebWorks LLC. All rights reserved.


BellaOnline Editor