A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Action scripting Sound?

  1. #1
    Member
    Join Date
    Dec 2000
    Posts
    58
    hi,
    i have a puzzle game.... how can i script sounds to it???

    as in when the user places the puzzle piece is in the wrong place, it gives an error sound and when it's in the right place it gives a clap or some other congratulatory sound...

    can i also give a on mouse down click sound in the script along with the above sounds (when the user chooses a piece it makes another sound)or do i have to give it in my button mouse down frame???

  2. #2
    Member
    Join Date
    Sep 2000
    Posts
    93
    Try the sound object. You can play sounds, stop them, etc. through action script if you use the sound object. so you could have an if-statement that plays one or the other sound depending on what the user does....
    check out the flash help to find out how the sound object works.

  3. #3
    Member
    Join Date
    Dec 2000
    Posts
    58
    but what script can i write?

  4. #4
    Member
    Join Date
    Sep 2000
    Posts
    93
    Alright-

    ummm... first you have to create 2 new sound objects -- now attach your clapping-sound and the boo-sound to them, you can now control them through action script. Something like this:
    Code:
    mySnd1 = new Sound();
    mySnd2 = new Sound();
    mySnd1.attachSound("clapping");
    mySnd2.attachSound("booing");
    Make sure you give the sounds in your library an "export this symbol..." identifier (go to "linkage.." when right-clicking on your sound in the library). In my example these identifiers are "clapping" and "booing".

    Now you can write a function that gets executed when you drop your puzzle piece (so I guess when your script says "stop Drag" or something). Then you just call that function.

    The function would just check if the piece is in the right place then play one or the other sound!

    Code:
    function checkPosition(correct) {
      if (correct) {
        mySnd1.start();
      } else {
        mySnd2.start();
      }
    }
    something like that... hope this is clear...

  5. #5
    Member
    Join Date
    Dec 2000
    Posts
    58
    Thanks a lot ur script works real fine but i still got a problem......

    well, the problem is that if i place a wrong piece before the right one it does not give me the booing sound(mysnd1)
    the sound starts only after i have a right piece in place....and then it comes sometimes and does not come at other times(even for the same piece). I suppose there is an error somewhere in my script...can u tell me what i should check to rectify the error.
    if not the below script something else????????

    that's my script... i wonder if u follow it????

    mysnd1 = new Sound();
    mysnd2 = new Sound();
    mysnd1.attachSound("booing");
    mysnd2.attachSound("clap");
    if ((s<1) or (right_ctr == 16)) {
    right_ctr = 0;
    s = 0;
    for (i=1; i<17; i++) {
    eval("at"+i+"_setx") = 0;
    eval("at"+i+"_sety") = 0;
    }
    }
    function addscore () {
    right_ctr = right_ctr+1;
    s = s+10;
    mySnd2.start();
    if (right_ctr == 16) {
    gotoAndPlay ("level3score");
    score2 = s;
    }
    }
    function subscore () {
    if (s>=10) {
    s = s-10;
    mySnd1.start();
    }
    }
    stop ();



Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center