ForumsProgramming ForumMusic on/off

8 3228
MilkyCheese2
offline
MilkyCheese2
20 posts
Nomad

I'm after music playing on frame 4, but if at any time a key is pressed (say 'M' the music will stop (and restart if pressed again) and then whatever state it's in it should stop on the last frame (I'm guessing StopallSounds will do that).

So all I need is a code that starts and stops the music. Can anyone help?

  • 8 Replies
LonLonRanch
offline
LonLonRanch
172 posts
Nomad

I don't exactly understand what you're looking for. Do you want toggle music (on/off) when you press the M key? And what do you mean by 'I'm after music playing on frame 4'?

I'm assuming your playing the music within a keyframe, if so you may want to try pulling the sound file in from the library with actionscript Sound class.

MilkyCheese2
offline
MilkyCheese2
20 posts
Nomad

Yes, I was playing the music with a keyframe, hanks a tonne for your help.

LonLonRanch
offline
LonLonRanch
172 posts
Nomad

Ok well another way to call a sound file (which would work better if you're using a key press) is to:

1st: Right click the sound file, click on 'Linkage' and then click the 'export for Actionscript' button and name it whatever you want ('mySound' for example).

Then you can now make an instance of it in your actionscript by putting code like this on the main timeline:

<i>var soundname:Sound = new Sound();
soundname.attachSound("mySound&quot;</i>

Then you can call the following functions to call that sound to start or stop:
<i>
soundname.start(0, 0);
soundname.stop();
</i>

Hope it helps, let me know if you don't understand how to use this, and please be specific

LonLonRanch
offline
LonLonRanch
172 posts
Nomad

Hmm sorry, ignore the <i> tags, I thought this forum used HTML :P

MilkyCheese2
offline
MilkyCheese2
20 posts
Nomad

Thanks for all the help. The reason I need to know these things is because I'm fairly new to flash. So yah, much thanks on all the scripting help.

LonLonRanch
offline
LonLonRanch
172 posts
Nomad

No problem we all start somewhere.

Klaushouse
offline
Klaushouse
2,770 posts
Nomad

should be
soundname.start(99999, 0);

keeps it looping 99999 times. Unless 0 is infinite which I didn't know.

LonLonRanch
offline
LonLonRanch
172 posts
Nomad

Good point, if you are using loopable music you should use a high number for the first parameter (such as 99999), otherwise if you want the sound to happen only once use 0.

Showing 1-8 of 8