Skip to main content
Participant
February 14, 2016
Question

Help pls. (mp3 using flash)

  • February 14, 2016
  • 1 reply
  • 292 views

Im not really familiar with adobe flash and especially coding.so pls bear with me T.T

i managed to search for a working code for pause/start/play buttons for my mp3.

here is the code:

stop();

var mySound:Sound;

var myChannel:SoundChannel;

var soundIsPlaying:Boolean = false; //prevent play btn overlap

var p:uint = 0;

mySound = new Sound;

mySound.load(new URLRequest("Fall Out Boy - Beat It ft. John Mayer.mp3"));

btn_play.addEventListener(MouseEvent.CLICK, playSound);

btn_stop.addEventListener(MouseEvent.CLICK, stopSound);

btn_pause.addEventListener(MouseEvent.CLICK, pauseSound);

function stopSound(myEvent:MouseEvent):void {

myChannel.stop();

p = 0;

soundIsPlaying = false;

}

function playSound(myEvent:MouseEvent):void {

if (!soundIsPlaying) {

myChannel = mySound.play(p); //play song location (p)

soundIsPlaying = true;

  }

}

function pauseSound(myEvent:MouseEvent):void {

if (soundIsPlaying) {

p = Math.floor(myChannel.position);

myChannel.stop();

soundIsPlaying = false;

}

}

//prev and next buttons//

btn_next.addEventListener(MouseEvent.CLICK, MightWork);

function MightWork(event:MouseEvent):void

{

  nextFrame();

}

btn_prev.addEventListener(MouseEvent.CLICK, MightNot);

function MightNot(event:MouseEvent):void

{

  prevFrame();

}

im going to make five frames, with five different songs on the action script. but when i press previous or next button. my songs would overlap each other...

"SoundMixer.stopAll()" wont work for me... pls help.

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
February 14, 2016

stop();

var mySound:Sound;

var myChannel:SoundChannel;

var soundIsPlaying:Boolean = false; //prevent play btn overlap

var p:uint = 0;

mySound = new Sound;

mySound.load(new URLRequest("Fall Out Boy - Beat It ft. John Mayer.mp3"));

btn_play.addEventListener(MouseEvent.CLICK, playSound);

btn_stop.addEventListener(MouseEvent.CLICK, stopSound);

btn_pause.addEventListener(MouseEvent.CLICK, pauseSound);

function stopSound(myEvent:MouseEvent):void {

myChannel.stop();

p = 0;

soundIsPlaying = false;

}

function playSound(myEvent:MouseEvent):void {

if (!soundIsPlaying) {

myChannel = mySound.play(p); //play song location (p)

soundIsPlaying = true;

  }

}

function pauseSound(myEvent:MouseEvent):void {

if (soundIsPlaying) {

p = Math.floor(myChannel.position);

myChannel.stop();

soundIsPlaying = false;

}

}

//prev and next buttons//

btn_next.addEventListener(MouseEvent.CLICK, MightWork);

function MightWork(event:MouseEvent):void

{

myChannel.stop();

  nextFrame();

}

btn_prev.addEventListener(MouseEvent.CLICK, MightNot);

function MightNot(event:MouseEvent):void

{

myChannel.stop();

  prevFrame();

}

DelPhinumAuthor
Participant
February 14, 2016

thanks for helping me...the code you suggested managed to stop the overlapping of songs by pressing the "next or previous" buttons, and then clicking play..but if i'm going to click the "stop or pause" buttons in one of my songs it would overlap again. do you know any other way?.. thanks again, you've been a big help

kglad
Community Expert
Community Expert
February 14, 2016

not unless you're using some code you're not showing.

in that case, make sure you use

if(myChannel){

myChannel.stop();

}

before you execute

myChannel=whatever.play(();