ForumsProgramming ForumFlash play button... twisted

1 3003
forgottongaurdian
offline
forgottongaurdian
42 posts
Nomad

hey all,

i wanna know how to make a button play a sound from the library when clicked... thats all...


thanks

  • 1 Reply
Klaushouse
offline
Klaushouse
2,770 posts
Nomad

Well you don't really specify a language. AS2 or AS3?

in AS2 it's this

var yourSound:Sound = new Sound();
yourSound.attachSound("theSound"
yourSound.start(0,0);

To explain, first line creates an empty sound variable, which is named yourSound, or whatever you so choose. Second line associates this sound with a sound in library. Now to do so, right click the sound in the library and click on linkage, then in the Identifier box put in the name you want the sound to be related to, in this case it's theSound, and check Export for ActionScript. Then the third line plays the sound. The first variable(0) is how many seconds to offset it by, as in how many seconds to start in. An example is if you have a 10 second sound clip and you set it as (1,0) it will start playing the sound at the 1 second mark as opposed to 0. The second variable is how many times to loop the sound, 0 plays it once, 1 plays it twice, 2 plays it three times, etc.



Someone correct me if I am wrong but for AS3 it's

var yourSound:theSound = new theSound();
yourSound.play();

Same steps as in before, but step 1 and 2 are condensed to 1 line instead of two. You still need to set identifier in this also don't forget.

Showing 1-1 of 1