I'm trying to create a flash for Clock Day and I need an Actionscript to toggle the sound by pressing the "M" key on the keyboard. Switching the music from mute to sound. I am also using AS2, does anyone have the code for this?
I'm trying to create a flash for Clock Day and I need an Actionscript to toggle the sound by pressing the "M" key on the keyboard. Switching the music from mute to sound. I am also using AS2, does anyone have the code for this?
At 7/23/11 12:24 PM, Hacsev wrote: I'm trying to create a flash for Clock Day and I need an Actionscript to toggle the sound by pressing the "M" key on the keyboard. Switching the music from mute to sound. I am also using AS2, does anyone have the code for this?
At 7/23/11 01:39 PM, scearezt wrote:At 7/23/11 12:24 PM, Hacsev wrote: I'm trying to create a flash for Clock Day and I need an Actionscript to toggle the sound by pressing the "M" key on the keyboard. Switching the music from mute to sound. I am also using AS2, does anyone have the code for this?You're welcome.
Yeah, not exactly. I am still in the basics of programming. Where do I put all this code? On a frame, on a movie clip? Where can I change (or at least see and add) the "Variable" name of the song that is in my library? This is still not clear to me.
At 7/23/11 03:23 PM, Hacsev wrote:At 7/23/11 01:39 PM, scearezt wrote:Yeah, not exactly. I am still in the basics of programming. Where do I put all this code? On a frame, on a movie clip? Where can I change (or at least see and add) the "Variable" name of the song that is in my library? This is still not clear to me.At 7/23/11 12:24 PM, Hacsev wrote: I'm trying to create a flash for Clock Day and I need an Actionscript to toggle the sound by pressing the "M" key on the keyboard. Switching the music from mute to sound. I am also using AS2, does anyone have the code for this?You're welcome.
These are dynamic functions, you must set up an SFX boolean variable, if true, then it palys the SFXs else not.
To call it, simply type this:
playSound("mysound", 100);//the first is the sound file's name in the library, you must check the EXPORT FOR ACTONSCRIPT [ ] to get it work... The second one is the volume of the sound. 0-100.
Put the function to the main timeline...
At 7/23/11 03:28 PM, scearezt wrote:At 7/23/11 03:23 PM, Hacsev wrote:These are dynamic functions, you must set up an SFX boolean variable, if true, then it palys the SFXs else not.At 7/23/11 01:39 PM, scearezt wrote:Yeah, not exactly. I am still in the basics of programming. Where do I put all this code? On a frame, on a movie clip? Where can I change (or at least see and add) the "Variable" name of the song that is in my library? This is still not clear to me.At 7/23/11 12:24 PM, Hacsev wrote: I'm trying to create a flash for Clock Day and I need an Actionscript to toggle the sound by pressing the "M" key on the keyboard. Switching the music from mute to sound. I am also using AS2, does anyone have the code for this?You're welcome.
To call it, simply type this:
playSound("mysound", 100);//the first is the sound file's name in the library, you must check the EXPORT FOR ACTONSCRIPT [ ] to get it work... The second one is the volume of the sound. 0-100.
Put the function to the main timeline...
This is the part where I am confused, where exactly do I find the "Export for Actionscript" screen? Remember, I'm still a noob. It could be right in my nose, and I would still not be able to figure it out.
At 7/23/11 04:28 PM, scearezt wrote: Essential ActionScript 2.0 by Colin Moock
Essential ActionScript 3.0 by Colin Moock
ActionScript 3.0 Game Programming University (2nd Edition)
Honestly, you are not helping at all. I'm not here to purchase books. This is so far the actionscript I am putting in a movie clip, since the code you gave me won't work:
onClipEvent (load) {
_root.parago.start(0, 1);
}
This doesn't seem to work because it won't recognize the sound. I put in the library "Export: parago". So I don't even know what is going on.
At 7/23/11 04:40 PM, Hacsev wrote:At 7/23/11 04:28 PM, scearezt wrote: Essential ActionScript 2.0 by Colin MoockHonestly, you are not helping at all. I'm not here to purchase books. This is so far the actionscript I am putting in a movie clip, since the code you gave me won't work:
Essential ActionScript 3.0 by Colin Moock
ActionScript 3.0 Game Programming University (2nd Edition)
onClipEvent (load) {
_root.parago.start(0, 1);
}
This doesn't seem to work because it won't recognize the sound. I put in the library "Export: parago". So I don't even know what is going on.
Well, if you are not prepared to learn. Don't ask silly questions. 'I am not here to buy books', that made me laugh. He was basically saying 'Hey, go learn some AS3 by using the MANY tutorials avaliable!'. You are not even willing to do that?
seriously, I am sick and tired of all those hateful comments, like "go and learn, rather than ask", "google it" - you either answer his question, or you simply GET OUT >:(
To import a soundclip from your library, right-click it in your library, click on Linkage... and in there, check Export for ActionScript, and then in the Identifier text field, type for example parago. Click OK! Now, your soundclip can be exported using actionscript. So, click on the Frame you want to use your soundclip, and use this actionscript on that frame:
sound = new Sound(); // make a new sound object
sound.attachSound("parago"); // we attach the soundclip we linked in the library
sound.start(0, 1); // change 1 to how many times you want to loop the song
And now, when you want to mute the soundclip, simply use this code when key M is pressed, like on your frame, you can use this code:
on_off = false;
// we make a boolean (false or true variable), to turn the volume on and off using same button
if(Key.isDown(77)){ // if key M is down
if(on_off == false){ // if our boolean is equals to false
_root.parago.setVolume(0); // turn down the volume, aka, mute it
on_off = !on_off; // make our boolean the opposite of itself (if it was false, it will turn true, and vice versa)
} else { // but if our boolean is equals to true
_root.parago.setVolume(100); // turn up the volume
on_off = !on_off; // change to opposite
}
}
include another line of _root.my_sound.setVolume(); for each suond you include :)
Hope this helps you, and gets you somewhere ;)
Well, he must learn the basics before he try to program anything, learn how to use your program. Then the language.
At 7/23/11 05:17 PM, Prid-Outing wrote: seriously, I am sick and tired of all those hateful comments, like "go and learn, rather than ask", "google it" - you either answer his question, or you simply GET OUT >:(
I completely agree with you. I was waiting for a user like you to come by.
To import a soundclip from your library, right-click it in your library, click on Linkage... and in there, check Export for ActionScript, and then in the Identifier text field, type for example parago. Click OK! Now, your soundclip can be exported using actionscript. So, click on the Frame you want to use your soundclip, and use this actionscript on that frame:
I actually did it. Apparently I had to click on the advance settings for the linkage screen to open, lol.
sound = new Sound(); // make a new sound object
sound.attachSound("parago"); // we attach the soundclip we linked in the library
sound.start(0, 1); // change 1 to how many times you want to loop the song
So far this part is working perfectly since I already changed the linkage.
And now, when you want to mute the soundclip, simply use this code when key M is pressed, like on your frame, you can use this code:
The rest of this code is not working correctly. I press the M key, but it does not do anything. Is it compatible to AS2? Or does it not work on frames?
Oh yeah, sorry XD
We need to assign a loop to keep checking if the M key is down :P
So, around my last code, use this code at the beginning:
onEnterFrame = function(){
// the code above goes here
}
Hope this helps :D
At 7/23/11 06:22 PM, Prid-Outing wrote: Oh yeah, sorry XD
We need to assign a loop to keep checking if the M key is down :P
So, around my last code, use this code at the beginning:
onEnterFrame = function(){
// the code above goes here
}
Hope this helps :D
So wait, does the code go like this? Because it is still not working with that last code you gave me.
sound = new Sound(); // make a new sound object
sound.attachSound("parago"); // we attach the soundclip we linked in the library
sound.start(0, 999); // change 1 to how many times you want to loop the song
onEnterFrame = function(){
on_off = false;
if(Key.isDown(77)){
if(on_off == false){
_root.parago.setVolume(0); // turn down the volume, aka, mute it
on_off = !on_off; // make our boolean the opposite of itself (if it was false, it will turn true, and vice versa)
} else { // but if our boolean is equals to true
_root.parago.setVolume(100); // turn up the volume
on_off = !on_off; // change to opposite
}
}
}
Almost, just make sure the on_off boolean is OUTSIDE our loop, or it will always remain false:
sound = new Sound(); // make a new sound object
sound.attachSound("parago"); // we attach the soundclip we linked in the library
sound.start(0, 999); // change 1 to how many times you want to loop the song
on_off = false;
onEnterFrame = function(){
if(Key.isDown(77)){
if(on_off == false){
_root.parago.setVolume(0); // turn down the volume, aka, mute it
on_off = !on_off; // make our boolean the opposite of itself (if it was false, it will turn true, and vice versa)
} else { // but if our boolean is equals to true
_root.parago.setVolume(100); // turn up the volume
on_off = !on_off; // change to opposite
}
}
}
Yeah, let's throw him as much code as we possibly can, that will help.
Or you can ya know, take 10sec out of your day and ya know, do some research. Written tutorial, video tutorial.
Don't come here asking for help when you can't be arsed to even try yourself.
Don't ban me again damnit I posted links. 3:<
At 7/23/11 07:22 PM, Prid-Outing wrote: Almost, just make sure the on_off boolean is OUTSIDE our loop, or it will always remain false:
For some reason it still does not work. Did you test it with a flash of yours? There must be something wrong.
I created something different using two separate frames. One that plays audio and the other one that stops it. But the problem is that since it is with the "if (Key.isDown(77)) _root.raw.gotoAndStop(2);" and the same vice versa but with 1 it seems that if you hold the key it keeps repeating the frames until you let go. So you can either get the audio again or stop it and the same vice versa.
At 7/23/11 08:25 PM, MintPaw wrote: Yeah, let's throw him as much code as we possibly can, that will help.
Or you can ya know, take 10sec out of your day and ya know, do some research. Written tutorial, video tutorial.
Yes, but as you can see, I already know how to stop and play audio by clicking the buttons. I just want to do it by pressing the M key on the keyboard.
I am sooo sorry, lol :P
if(on_off == false){
_root.parago.setVolume(0);
on_off = !on_off;
} else {
_root.parago.setVolume(100);
on_off = !on_off;
}
It shouldn't be parago, because that's the attached sound's linkage name. Change parago to sound, because that's the name of your sound object - lol, sorry :P
This should be the whole code - I've added a anti-repeat code to it. If you hold down the M button, the sound won't keep turning on and off:
sound = new Sound();
sound.attachSound("parago");
sound.start(0, 999);
on_off = false;
down = false;
onEnterFrame = function(){
if(Key.isDown(77)){
if(down == false){
down = true;
if(on_off == false){
_root.sound.setVolume(0);
on_off = !on_off;
} else {
_root.sound.setVolume(100);
on_off = !on_off;
}
}
} else {
down = false;
}
}
Again, sorry, it was my fault :P
At 7/24/11 12:04 AM, Prid-Outing wrote: This should be the whole code - I've added a anti-repeat code to it. If you hold down the M button, the sound won't keep turning on and off:
It worked perfectly, although for some reason it will only work on the first frame, when I need it to work on the 3rd frame as well. If I don't mute the song at the beginning I cannot mute it on Frame 3. And if I do mute it at the beginning, I cannot play the song on Frame 3 with the M key.
At 7/24/11 09:00 AM, Hacsev wrote:At 7/24/11 12:04 AM, Prid-Outing wrote: This should be the whole code - I've added a anti-repeat code to it. If you hold down the M button, the sound won't keep turning on and off:It worked perfectly, although for some reason it will only work on the first frame, when I need it to work on the 3rd frame as well. If I don't mute the song at the beginning I cannot mute it on Frame 3. And if I do mute it at the beginning, I cannot play the song on Frame 3 with the M key.
Then make a new layer just for the sound, and it should only contain of a single key frame, but the keyframe's length, should be as long as all of your frames. And on that long keyframe, paste the code above ;)
At 7/24/11 09:42 AM, Prid-Outing wrote:At 7/24/11 09:00 AM, Hacsev wrote:Then make a new layer just for the sound, and it should only contain of a single key frame, but the keyframe's length, should be as long as all of your frames. And on that long keyframe, paste the code above ;)At 7/24/11 12:04 AM, Prid-Outing wrote: This should be the whole code - I've added a anti-repeat code to it. If you hold down the M button, the sound won't keep turning on and off:It worked perfectly, although for some reason it will only work on the first frame, when I need it to work on the 3rd frame as well. If I don't mute the song at the beginning I cannot mute it on Frame 3. And if I do mute it at the beginning, I cannot play the song on Frame 3 with the M key.
Already tried that and it still won't work, I even tried making a movie clip with the code on the first frame and only the sound code will work, it won't mute no matter what. I think it has to do something to do with the linkage since it says "Export to Frame 1" and nothing else.
The Export in Frame 1 has nothing to do with this, lol. That's only if you don't want to export the sound to stage on Frame 1, preventing the white screen even if there's a loading, so that the preloader may load the sound that's going to be exported :)
Anyways, make that movieclip of yours again, and put it in a single-keyframed layer, which is as long as all of your frames, just like you did, but the code within the M Key.isdown, contains the _root code, which will then go to the root of the movie, which is outside of our movieclip. So, remove the _root code from your code, and it'll look something like this inside your movieclip's frame actions:
sound = new Sound();
sound.attachSound("parago");
sound.start(0, 999);
on_off = false;
down = false;
onEnterFrame = function(){
if(Key.isDown(77)){
if(down == false){
down = true;
if(on_off == false){
sound.setVolume(0);
on_off = !on_off;
} else {
sound.setVolume(100);
on_off = !on_off;
}
}
} else {
down = false;
}
}
At 7/24/11 10:02 AM, Prid-Outing wrote: Anyways, make that movieclip of yours again, and put it in a single-keyframed layer, which is as long as all of your frames, just like you did, but the code within the M Key.isdown, contains the _root code, which will then go to the root of the movie, which is outside of our movieclip. So, remove the _root code from your code, and it'll look something like this inside your movieclip's frame actions:
It finally worked! I appreciate all your help Prid-Outing, maybe I should put you in the credits section for helping me, lol. Thanks again!