A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Playing a soundeffect on a hitTest

  1. #1
    Member
    Join Date
    Mar 2004
    Location
    Holland
    Posts
    59

    Playing a soundeffect on a hitTest

    Hello people.
    Lately I have been trying to make a pacman-like game in flash, which mainly consist of a character walking through a maze collecting items. I would like to hear a bleeping sound whenever he touches one but I have no idea how to script this.

    Can anyone help me out?

    This is the script regarding my items (pills):

    for (a=1; a<=11; a++) {
    if (pacman.hitTest(this["pil"+a])) {
    if (raak == false) {
    this["pil"+a]._x = 10000;
    score = score+100;
    pillen = pillen-1;

    Thanks in advance

    Edit: Forgot to mention I'm using flash MX 2004 and flash 8 (Don't think there's a difference in scripting? Not sure.).
    Becoming a flash master, one question at a time.

  2. #2
    Senior Member Bernz's Avatar
    Join Date
    Jun 2005
    Location
    Mid-Eastern U.S.
    Posts
    161
    Use the Sound class.

    Look up the sound class in your version of flash at http://livedocs.macromedia.com/

    The code is:
    Code:
    beep = new Sound();
    beep.attachSound("beep.wav");
    beep.start();
    where beep is the name of the sound object, and "beep.wav" is the identifier name of the sound.

    There's something else you have to do:
    Right-click on the sound in your library and select "linkage...". Next, check the box next to "export for ActionScript".

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