A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: stopping a sound file, Please help!!!!

Threaded View

  1. #1
    Junior Member
    Join Date
    Apr 2010
    Posts
    3

    stopping a sound file, Please help!!!!

    Hi i have a program that allows me to press a key and it plays a sound here is the code:

    stage.addEventListener(KeyboardEvent.KEY_DOWN, myKeyDown);
    function myKeyDown(e:KeyboardEvent):void
    {
    if (e.keyCode == 65 ) // A
    {
    var MySound:Sound = new Soundfile();
    MySound.play();
    }
    }

    This works fine but if i press the a key again before the sound has finished i want it to stop the sound and start it again. I thought i could do it like this:

    function myKeyDown(e:KeyboardEvent):void
    {
    if (e.keyCode == 65 ) // A
    {

    var MySound:Sound = new Soundfile();
    MySound.stop();
    MySound.play();
    }
    }

    by stopping the sound before i start it that way if it is playing and the key is hit it will stop and start again, i get this error though:

    Error #1006: stop is not a function.

    please please can someone help with this. oh iam using cs4 as3
    Last edited by Flashnoobee; 04-20-2010 at 01:34 PM. Reason: missed out what version iam using

Tags for this Thread

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