Flash MX Virgin - On/Off switch for streaming mp3 file

Can anyone help me out with a problem I have regarding
actionscript. What I am trying to do is create a button that
switches a streaming mp3 file on/off (Stop/Play).

I want a single button that if pressed when the music is
playing, switches off the music. If pressed when the music
has been stopped, plays the music again.

I am stuck because I don’t know how to keep track of if the
music is on or off. At the beginning of the movie the music
will play automatically, I have placed the code on a seperate layer in the main timeline. I was thinking of setting a
variable called ‘play’ to true at the beginning then I
realised that because the way flash works the variable will
be reset each time the play head gets to the beginning of
the movie.

I am new to flash and especially new to actionscript, can
anyone help me out with this?

Code :

mySound = new Sound();
mySound.loadSound(“loop.mp3”, isStreaming);
mySound.start();

All this does is play/stream the mp3 file on startup.

Thanks.

Take a look at this…

http://www.kirupaforum.com/forums/showthread.php?s=&threadid=24137&highlight=mp3+on+off

TD

*Originally posted by tobydog *
**Take a look at this…

http://www.kirupaforum.com/forums/showthread.php?s=&threadid=24137&highlight=mp3+on+off

**

Thanks for helping me out but that still doesn’t really solve my problem.

All I am after is one button that is going to act as a on/off switch. I only want one button so I need to have some kind of way to keep track of if the music is currently playing. Otherwise I will not know if I should be playing the music or stopping it.

(taken from macromedia.com)

You can do this by changing the button itself, such as hiding one button and showing another, or putting the button in a movie clip and jumping to another frame where it has another script. But a simpler way is to use a variable flag in the script to tell which state the button is currently in. Here’s an example:


on (release) {

   //  Toggle a flag between TRUE and FALSE:
   IamActive = not IamActive;

   //  Do different things depending on flag's current state:
   if (IamActive) {
      //  various actions to be performed for "on" state of button
   } else {
      //  various actions to be performed for "off" state of button
   }

}

btw… when will you’re not a virgin anymore?? :stuck_out_tongue:

*Originally posted by indojepang *
**(taken from macromedia.com)

on (release) {

// Toggle a flag between TRUE and FALSE:
IamActive = not IamActive;

// Do different things depending on flag’s current state:
if (IamActive) {
// various actions to be performed for “on” state of button
} else {
// various actions to be performed for “off” state of button
}

}

 **
 

Thanks for the reply.

I'm still a bit confused what the following line does 'IamActive = not IamActive;'. Is 'IamActive' a property of a button? 

Thanks for the tip about swapping the buttons around. I think I have figured out a way to do it.

(1). Movie starts with music playing
(2). Playing Button is shown.
                   
Playing Button :-
                    'On Release'
                    Stop Music
                    Hide Playing Button
                    Show Off Button'

Off Button :-
                  'On Release'
                  Play Music
                  Hide Off Button
                  Show Playing Button

This will work won't it?

Thanks.

http://www.delusionalfx.com/tutorials/xternalsound.htm

cant really explain much better then there. follow my article (which it looks like you did), and post your fla, i will help you

but recheck your isStreaming code. that is wrong, replace with true;

in case ur lazy :slight_smile:

[AS]
on(release){
if(playing!=true){ // if playing is not true… meaning if our mp3 is not loaded
x.loadSound(“na.mp3”,true);// load our mp3
x.start(0,999);
playing = true;// declaring that our mp3 is in fact playing
}
}
[/AS]

or putting the button in a movie clip and jumping to another frame where it has another script

take a look at the fla…

*Originally posted by indojepang *
**take a look at the fla… **

i believe he is trying to load full mp3’s

I want a single button that if pressed when the music is
playing, switches off the music. If pressed when the music
has been stopped, plays the music again.

don’t care about loading thing…:stuck_out_tongue:

hey Digital!!! are u a singer??

well either way will work:) i try not to load and unload sound by going to different frames, but you can. I do it via AS as it is much neater

Oh and no I am not a singer, I just love music

Thanks to everyone who has taken the time to help me out. I have now got it working exactly how I wanted it :slight_smile:

As indojepang suggested I used the swap buttons technique. Basically it works as follows:

  1. Movie loads with a streaming mp3 file (400k) playing in the background.

  2. A animated button is shown to represent the music play, in my case it’s a pair of earphones with a few wavy lines animating in the middle.

  3. The user can then click on the button to turn of the music. When the button is clicked , the music is turned off and the animated buttons visibility is set to false (to hide it). Another button underneath is then made visible in exactly the same space as the previous button.

  4. When the user clicks this new button, the music starts playing again. The current button is hidden and the animated button is shown again.

Simple =)

It looks like one button is being used to turn the sound on and off but it’s actually two.

Digitalosophy :

but recheck your isStreaming code. that is wrong, replace with true;

I think you can either specify true or just enter ‘isStreaming’. I got this from the FlashMX help guide. I think they both do the same.

indojepang:

Love the speaker animation, do you mind if I use it or copy it and make a few little changes. At the moment I have a animated headphone but i’m not sure if I like the look of it yet.

Anyway thanks yet again to everyone who helped me out. I am working on my first ever flash site and am slowly getting there. I’m sure i’ll be back soon asking how to create a preloader =)

Cheers.

glad to see it’s working

the speaker animation? be my guest…

i bet Digitalosophy love hip & hardcore…:slight_smile:

hip hop was good, not sure what happened lately :slight_smile: rok is where it’s at