Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8764023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:55:41+00:00 2026-06-13T15:55:41+00:00

I’ve created a few buttons in Flash. I’m trying to make it so that

  • 0

I’ve created a few buttons in Flash. I’m trying to make it so that if you click one button, the audio starts playing for that button. If you click another button, the active audio stops and the new audio of the button you clicked last start playing.

Any help please?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T15:55:42+00:00Added an answer on June 13, 2026 at 3:55 pm

    What you’re describing is actually quite easy to do.

    First things first, I recommend importing the audio into your Flash project. Alternatively, there is a way to play it directly from an external file. This is beyond the scope of my answer, so if you need help on that, you should post a question specifically covering it.

    Assuming you have imported the audio file into your Flash project’s library, make an as3 instance of it. (Right click the file in the library, click Properties –> ActionScript [tab] –> [Check] Export for ActionScript & [Enter name in] Class)

    Now, create a definition of the sound in your code. (Assuming your two sounds were named “mySound1” and “mySound2” in the Class field of the previous step.)

    var mySound1:Sound = new mySound1();
    var mySound2:Sound = new mySound2();
    

    Now, define your sound channel.

    var mySoundChannel:SoundChannel = new SoundChannel();
    

    There are two alternate ways of stopping one sound and playing another. The first is to create one function that does both every time. The second method is to create two formulas, one for “play” and one for “stop”. You will need to decide which method works best for you. I’ll use the two-function method below:

    function stopSound():void
    {
       //This stops all sound in the sound channel. 
       //If there is nothing playing, nothing happens.
       mySoundChannel.stop();
    }
    
    //In this function, we create an argument that allows us to tell the function 
    //what sound to we want it to play.
    function playSound(soundname:String):void
    {
       mySoundChannel = this[soundname].play(0, 0);
    }
    

    [Note, you can tweak the play() properties to meet your needs, doing things like starting in the middle of the song, or looping it forever. 0,0 starts at the beginning, and doesn’t loop. See the documentation for this.]

    Now you hook up the event listeners for the buttons. (If you need help with event listeners, read the documentation.)

    myButton1.addEventListener(Mouse.CLICK, btn1Click);
    myButton2.addEventListener(Mouse.CLICK, btn2Click);
    
    function btn1Click(evt:Event):void
    {
       stopSound();
       playSound(mySound1);
    }
    
    function btn2Click(evt:Event):void
    {
       stopSound();
       playSound(mySound2);
    }
    

    This should be enough information to get you started. In my game core, I actually have a custom class for dealing with sound playback that gives me the ability to repeat sounds, change volume, and keep sounds from conflicting with each other. I say that to emphasize that you can do quite a bit with the sound class. Do some digging in that documentation for ideas and help.

    You may also consider putting a try-catch statement in the playSound function, since it will throw an reference error if you pass a name for a sound that doesn’t exist.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.