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

  • SEARCH
  • Home
  • 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 7697861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:06:31+00:00 2026-05-31T22:06:31+00:00

I’m having trouble trying to manipulate music using buttons I can’t seem to make

  • 0

I’m having trouble trying to manipulate music using buttons

  1. I can’t seem to make music1 autoplay and loop when the movie starts.

  2. I want to stop music1 and play music2 when I press a button:

    • music1 in main timeline
    • button to change music is inside a movie clip

so far here is the code I found on the internet but I’m not sure how I can change it to do what I need:

var mySound:Sound;
var myChannel:SoundChannel;
var isPlaying:Boolean = false;
var isPaused:Boolean = false;
var p:uint = 0;
var songfile:String;
var songtitle:String;

song1_btn.addEventListener(MouseEvent.CLICK, playSound);
song2_btn.addEventListener(MouseEvent.CLICK, playSound);
song3_btn.addEventListener(MouseEvent.CLICK, playSound);
stop_btn.addEventListener(MouseEvent.CLICK, stopSound);
pause_btn.addEventListener(MouseEvent.CLICK, pauseSound);

function stopSound(myEvent:MouseEvent):void {
    if (isPlaying) {
        myChannel.stop();
        p = 0;
        isPlaying = false;
        isPaused = false;
    }
}

function playSound(myEvent:MouseEvent):void {
    switch(myEvent.target.name) {
        case "song1_btn":
            songfile = "bgm1.mp3";
            songtitle = "one";
            break;
        case "song2_btn":
            songfile = "bgm2.mp3";
            songtitle = "two";
            break;
        case "song3_btn":
            songfile = "bgm3.mp3";
            songtitle = "Three";
            break;
    }
    mySound = new Sound;
    mySound.load(new URLRequest(songfile));
    title_txt.text = songtitle;
    if (isPlaying) {
        myChannel.stop();
        myChannel = mySound.play(0);
    } else {
        myChannel = mySound.play(0);
        isPlaying = true;
    }
}

function pauseSound(myEvent:MouseEvent):void {
    if (isPlaying) {
        p = Math.floor(myChannel.position);
        myChannel.stop();
        isPlaying = false;
        isPaused = true;
    } else if (isPaused) {
        myChannel = mySound.play(p);
        isPlaying = true;
        isPaused = false;
    }
}

title_txt.text = "This text will be replaced.";

Note: this code is in the main timeline.

  • 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-05-31T22:06:32+00:00Added an answer on May 31, 2026 at 10:06 pm

    I hope this code is similar to what you are looking for, I tried to keep things simple in case you want to modify anything to better suit your needs:

    var mySound:Sound;
    var myChannel:SoundChannel;
    
    //song files
    var music1:String="music1.mp3";
    var music2:String="music2.mp3";
    
    //initially load and loop music1
    loopMusic(music1);
    
    //button to change to music2 inside movieclip
    myMovieclip.myButton2.addEventListener(MouseEvent.CLICK, button2_handler);
    
    //button to change back to music1 inside movieclip
    //initially disabled since music1 is playing
    myMovieclip.myButton1.addEventListener(MouseEvent.CLICK, button1_handler);
    myMovieclip.myButton1.enabled=false;
    
    function loopMusic(songName:String):void
    {
      //stop music currently playing
      if(myChannel)
        myChannel.stop();
    
      //initialize sound var
      mySound = new Sound();
    
      //load song
      mySound.load(new URLRequest(songName));
    
      //set up event listener
      mySound.addEventListener(Event.COMPLETE, songLoaded_handler);
    
    }
    
    function songLoaded_handler(evt:Event):void 
    {
    //loop loaded song 
        myChannel = mySound.play(0, int.MAX_VALUE);
    }
    
    function button1_handler(e:Event):void
    {
        loopMusic(music1);
    
        //toggle buttons
        myMovieclip.myButton2.enabled=true;
        myMovieclip.myButton1.enabled=false;
    
    
    }
    
    function button2_handler(e:Event):void
    {
        loopMusic(music2);
    
        //toggle buttons
        myMovieclip.myButton1.enabled=true;
        myMovieclip.myButton2.enabled=false;
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I am trying to loop through a bunch of documents I have to put
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the

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.