-
[RESOLVED] Virtual piano
hi, i have a question here
i want to make a virtual piano for my class exam
i wonder to know, how to make the button can be pressed using keyboard, not mouse
please help me for the actionscript
thanks in advance
-
Prid - Outing
This can be hard to accomplish, but since you're using buttons, I'll have to give you a simpler, more suitable way. Import all your sounds to your Library, right-click on one sound, press Properties. In the box that appears, if not already, press Show Advanced, and then tick/check Export for ActionScript. Then, in the Identifier text field, type in the name of your note, for example, c, or c_sharp (only letters, numbers and underscores are allowed, and the first character should not be a number). Press OK to make this sound playable with actionscript, and repeat this for all of your sounds. Then, select one of your note buttons, for instance, C, press F9 to open Actions Panel, and type in this:
Actionscript Code:
on(keyPress "c", keyPress "C"){ sound = new Sound(); sound.attachSound("c"); sound.start(); }
The first line checks if they press the letter C on their keyboard (both, small C and capital C, in case they have CAPS Lock turned on), and if they do, create a new Sound Object, attach the sound with the Linkage ID c from the Library (the same name you input), and play it. Just copy and paste this to all the other buttons, but with a slight modification, for instance, for C#, you'd use this (I just chose F, because you can't play two sounds for one letter on keyboard):
Actionscript Code:
on(keyPress "f", keyPress "F"){ sound = new Sound(); sound.attachSound("c_sharp"); sound.start(); }
Now, this is a really bad way of doing it, but since you have made all the notes as buttons, you'll have to use this way. You could've done this in a much better way using key listeners, arrays and movieclips.
Hope this helps, nonetheless
I am back, guys ... and finally 18 :P
BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS
-
Originally Posted by Nig 13
This can be hard to accomplish, but since you're using buttons, I'll have to give you a simpler, more suitable way. Import all your sounds to your Library, right-click on one sound, press Properties. In the box that appears, if not already, press Show Advanced, and then tick/check Export for ActionScript. Then, in the Identifier text field, type in the name of your note, for example, c, or c_sharp (only letters, numbers and underscores are allowed, and the first character should not be a number). Press OK to make this sound playable with actionscript, and repeat this for all of your sounds. Then, select one of your note buttons, for instance, C, press F9 to open Actions Panel, and type in this:
Actionscript Code:
on(keyPress "c", keyPress "C"){ sound = new Sound(); sound.attachSound("c"); sound.start(); }
The first line checks if they press the letter C on their keyboard (both, small C and capital C, in case they have CAPS Lock turned on), and if they do, create a new Sound Object, attach the sound with the Linkage ID c from the Library (the same name you input), and play it. Just copy and paste this to all the other buttons, but with a slight modification, for instance, for C#, you'd use this (I just chose F, because you can't play two sounds for one letter on keyboard):
Actionscript Code:
on(keyPress "f", keyPress "F"){ sound = new Sound(); sound.attachSound("c_sharp"); sound.start(); }
Now, this is a really bad way of doing it, but since you have made all the notes as buttons, you'll have to use this way. You could've done this in a much better way using key listeners, arrays and movieclips.
Hope this helps, nonetheless
is that actionscript work for flash 8 ?
-
Prid - Outing
Flash 8 uses mainly Actionscript 2.0, and that code is also in the same language, so it yeah, it should work
I am back, guys ... and finally 18 :P
BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS
-
Originally Posted by Nig 13
Flash 8 uses mainly Actionscript 2.0, and that code is also in the same language, so it yeah, it should work
can you give me an fla example ?
-
Prid - Outing
So the double on(keypress) didn't work, so you'll just have to stick with lowercase letters and tell the user to turn off CAPS lock or not use SHIFT.
DOWNLOAD EXAMPLE FILE
I am back, guys ... and finally 18 :P
BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS
-
Originally Posted by Nig 13
So the double on(keypress) didn't work, so you'll just have to stick with lowercase letters and tell the user to turn off CAPS lock or not use SHIFT.
DOWNLOAD EXAMPLE FILE
thank you my master
can i ask you anytime i need help ?
if u dont mind
-
Originally Posted by Nig 13
So the double on(keypress) didn't work, so you'll just have to stick with lowercase letters and tell the user to turn off CAPS lock or not use SHIFT.
DOWNLOAD EXAMPLE FILE
sir
but the animation didn't work
i try with "over" "down" "hit"
but the animation not work using keyboard, only work with mouse
-
Prid - Outing
oh, that won't work with Buttons, you'll then have to resort to using MovieClips instead, but then it would be more complex to include the button functionality with the mouse as well, but HERE YOU GO (notice the Frame Labels used to make the movieclips function as buttons as well)
Hope that helps
I am back, guys ... and finally 18 :P
BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS
-
Originally Posted by Nig 13
oh, that won't work with Buttons, you'll then have to resort to using MovieClips instead, but then it would be more complex to include the button functionality with the mouse as well, but HERE YOU GO (notice the Frame Labels used to make the movieclips function as buttons as well)
Hope that helps
its hope full
i still have many question
but i finish this one before i ask again
forgive if my english not so good
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|