SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Dec 2008
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sound problems, onclick button...

    I have series of buttons on the flash file. When each button is clicked I want a different sound to play. At the moment the code I am using will always play the sound associated with the last button instead of the sound it should. As if the code is not stopping.

    The code:

    Code Actionscript:
     
    var my_sound:Sound = new Sound();
    my_sound.loadSound("GrapeVine/Bass.mp3", false);
     
    on8_btn.onPress = function() {
    my_sound.start();
    };
    off8_btn.onPress = function() {
    my_sound.stop();
    };
     
    var my_sound:Sound = new Sound();
    my_sound.loadSound("GrapeVine/Guitars.mp3", false);
     
    on9_btn.onPress = function() {
    my_sound.start();
    };
    off9_btn.onPress = function() {
    my_sound.stop();
    };
     
    var my_sound:Sound = new Sound();
    my_sound.loadSound("GrapeVine/Drums.mp3", false);
     
    on10_btn.onPress = function() {
    my_sound.start();
    };
    off10_btn.onPress = function() {
    my_sound.stop();
    };
     
    var my_sound:Sound = new Sound();
    my_sound.loadSound("GrapeVine/Lead Vocal.mp3", false);
     
    on11_btn.onPress = function() {
    my_sound.start();
    };
    off11_btn.onPress = function() {
    my_sound.stop();
    };
     
    var my_sound:Sound = new Sound();
    my_sound.loadSound("GrapeVine/Organ_Electric Piano.mp3", false);
     
    on12_btn.onPress = function() {
    my_sound.start();
    };
    off12_btn.onPress = function() {
    my_sound.stop();
    };
     
    var my_sound:Sound = new Sound();
    my_sound.loadSound("GrapeVine/Strings_French Horns.mp3", false);
     
    on13_btn.onPress = function() {
    my_sound.start();
    };
    off13_btn.onPress = function() {
    my_sound.stop();
    };
     
    var my_sound:Sound = new Sound();
    my_sound.loadSound("GrapeVine/Tambourine_Conga.mp3", false);
     
    on14_btn.onPress = function() {
    my_sound.start();
    };
    off14_btn.onPress = function() {
    my_sound.stop();
    };
     
    var my_sound:Sound = new Sound();
    my_sound.loadSound("GrapeVine/Voices.mp3", false);
     
    on15_btn.onPress = function() {
    my_sound.start();
    };
    off15_btn.onPress = function() {
    my_sound.stop();
    };

    This code is in an actions layer. Why isn't the correct sound playing for each button?

    Would it be easier to put the code directly in the button and if so how would I do this, as I have previously received errors.

    Thanks.

  2. #2
    SitePoint Evangelist ferrari_chris's Avatar
    Join Date
    Mar 2008
    Location
    NP, New Zealand
    Posts
    576
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to give each sound a unique name rather than using the same sound object over and over again? Try something like this:

    Code Actionscript:
     
    var bass_snd:Sound = new Sound();
    bass_snd.loadSound("GrapeVine/Bass.mp3", false);
     
    on8_btn.onPress = function() {
    bass_snd.start();
    };
    off8_btn.onPress = function() {
    bass_snd.stop();
    };
     
    var guitars_snd:Sound = new Sound();
    guitars_snd.loadSound("GrapeVine/Guitars.mp3", false);
     
    on9_btn.onPress = function() {
    guitars_snd.start();
    };
    off9_btn.onPress = function() {
    guitars_snd.stop();
    };
     
    var drums_snd:Sound = new Sound();
    drums_snd.loadSound("GrapeVine/Drums.mp3", false);
     
    on10_btn.onPress = function() {
    drums_snd.start();
    };
    off10_btn.onPress = function() {
    drums_snd.stop();
    };
    and so on...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •