Community

Music on/off

Posted Jul 23, '08 at 12:43pm

MilkyCheese2

MilkyCheese2

9 posts

Wood - Squire

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?

Posted Jul 23, '08 at 12:47pm

LonLonRanch

LonLonRanch

151 posts

Gold - Squire

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.

 

Posted Jul 23, '08 at 12:53pm

MilkyCheese2

MilkyCheese2

9 posts

Wood - Squire

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

 

Posted Jul 23, '08 at 1:34pm

LonLonRanch

LonLonRanch

151 posts

Gold - Squire

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");</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

 

Posted Jul 23, '08 at 1:35pm

LonLonRanch

LonLonRanch

151 posts

Gold - Squire

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

 

Posted Jul 23, '08 at 1:46pm

MilkyCheese2

MilkyCheese2

9 posts

Wood - Squire

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.

 

Posted Jul 23, '08 at 1:59pm

LonLonRanch

LonLonRanch

151 posts

Gold - Squire

No problem :D we all start somewhere.

 

Posted Jul 23, '08 at 5:05pm

Klaushouse

Klaushouse

1,746 posts

Iron - Lord

should be
soundname.start(99999, 0);

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

 

Posted Jul 24, '08 at 2:28pm

LonLonRanch

LonLonRanch

151 posts

Gold - Squire

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.

 
Reply to Music on/off

You must be logged in to post a reply!