Skip to main content
markerline
Inspiring
September 23, 2013
Answered

How would I achieve this result? ActionScript 3

  • September 23, 2013
  • 1 reply
  • 1140 views

Dear Forum members:

How would I go about achieving the following result?

I have a Movie Clip that is in my Flash library.  It is essentially a button.  There is a switch which enables the functionality that when the button is switched to an active loading state, a user can load a sound from a Flash window or from the file system (depending on how I design it).  The switch gets turned off so that the sound stays locked to that button.  The trick is that there are many buttons (let's say 16 to celebrate the Microsoft Surface 2 Music Kit).

I can manually create 16 event listeners but that seems like wasted code lines.  Is there an automated way of adding a custom event listener to each of the 16 buttons that would load a different sound?  Need help in methodology here.  Thanks in advance, markerline

This topic has been closed for replies.
Correct answer robdillon

ButtonArray is a reference to an object in an array. It's not a loader. You'll have to create a loader object to do the loading. You should also create sound objects and load those sounds into the sound objects and then use the buttons to tell the sounds to play or stop.

1 reply

robdillon
Participating Frequently
September 23, 2013

1. Create an array to the references to the sound files.

2. Use a for... loop to create the instances of the button in the display list and

3. add the event listener for each button instance that references a single function

4. add each new button instance to a second array

5. In the function, use the currentTarget to find that button in the second array and then

6. load or play or stop the sound that is in the same position in the first array.

markerline
Inspiring
September 23, 2013

thank you.  using arrays sounds like the right idea.  just wasnt sure how to implement them.  i will try that and let you know how i fare along.

sincerely, markerline