Question:

Need help understanding action script code

by  |  earlier

0 LIKES UnLike

Okay so I searched on the internet on how to play a sound when a key is pressed and I came across this:

Hey,

first up, for all the seperate sounds you are going to use it needs to have a unique linkage to actionscript. Right click on a sound in your library and click linkage, now give it a unique and logical name and click Export for actionscript check box aswell. Do this for all of them.

Now, make a button. on (keyPress "c") {

New-name-here = new Sound();

New-name-here.attachSound("cannon");

_root.New-name-here.start();

}

Add that code. Now the word cannon is the unique name you gave the sound , change it to what sound you want to play. The c up top is the letter that needs to be pressed to hear the sound. And finally

New-name-here needs to be changed to a more suitable holder for that sound, in this case maybe 'cannonholder'

What does that mean? If it helps I am making a drum I named the linkage kick and the sound that I want to play is named tight_kick_017

 Tags:

   Report

1 ANSWERS


  1. 1. Get a bunch of sounds together and put them in your library. If you can't follow how to do this, stop now and review the Flash tutorial under the Help menu.

    2. Right-click on each sound in the Library and choose Linkage from the menu that pops up.

    3. Give each sound a specific, unique name. We will assume, for this explanation, that you have three sounds, named A, B and C. Make sure you have checked ON the box that says Export for ActionScript.

    4. Enter the code you were given in the Actions pane:

    on (keyPress "c") {

    New-name-here = new Sound();

    New-name-here.attachSound("cannon");

    _root.New-name-here.start();

    }

    5. Change New-name-here to be MySoundA.

    6. Change "cannon" to be "A"

    7. Change _root.New-name-here.start(); to be _root.MySoundA.start();

    That's it. Now, when you press the "c" key, sound A is played.

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions