Flash Tutorials
PDF Print E-mail

Attaching Data to a Button by Subclassing the ActionScript 3 Button Class

by David Salahi

At the October, 2008 OC Flash meeting someone raised the following question: How can you have multiple buttons that all call the same click event listener while still being able to identify which button was clicked? You could, of course, use a separate event listener for each button but this would require duplicating the event listener code. But duplicating code is something that should be avoided whenever possible. And, if you are creating multiple buttons dynamically at run-time, using multiple event listeners is not even possible as you can’t create new ActionScript code (new event listeners) at run-time.

The ButtonWithData project illustrates one way to solve the problem of distinguishing which of several buttons was clicked while using a single event listener for all buttons. This project contains two files, ButtonWithData.as that defines a new Button object with some attached data and a ButtonWithData.fla file that creates instances of the ButtonWithData object and places them on the stage. The FLA file also contains the event listener. Links to download the files are at the end of this article.

Last Updated on Friday, 24 October 2008 08:36
Read more...
 


 

Special Interest Groups (SIGs)

Digital Video

The Digital Video SIG brings together presentations on video editing and special effects software. The DV SIG meets on the fourth Tuesday of each month. Visit the DV SIG page.

Flash

OC Flash deals with all aspects of development using Adobe Flash. OC Flash meets on the first Tuesday of each month. Visit the OC Flash website.

Web Video Crossroads

The Web Video Crossroads SIG addresses all aspects of video on the web and mobile devices. Web designers, web developers, and video/audio producers are welcome to discuss the latest developments in this fast-changing industry. The Web Video Crossroads SIG meets on the second Thursday of each month. Visit the Web Video Crossroads SIG page.

ColdFusion

The OC Cold Fusion Users Group meets the third Wednseday each month to discuss server-side development using Adobe's ColdFusion language. Visit the OCCFUG website.