A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Stop sound file early (using Sound object)

  1. #1
    Junior Member
    Join Date
    Feb 2008
    Posts
    12

    Stop sound file early (using Sound object)

    I know I can use the play() method of the Sound object to offset the beginning of a sound. Ex:

    mySound.play(2000) - plays the sound beginning at 2 seconds

    Is there a way to get a sound to stop early? For example, if it is a 20-second sound, can I get it to stop at 18 seconds? Thanks!

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    import flash.events.*;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.net.URLRequest;

    var mySound:Sound = new Sound();
    mySound.load (new URLRequest("track2.mp3"));
    var channel:SoundChannel = mySound.play (0, 1);
    addEventListener(Event.ENTER_FRAME, fHandler);
    function fHandler(event:Event):void
    {
    trace(channel.position);
    if(channel.position>=18000)
    {
    channel.stop();
    }
    }
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    One thing I forgot. You should definitely remove the listener.
    if(channel.position>=18000)
    {
    channel.stop();
    removeEventListener(Event.ENTER_FRAME, fHandler);
    }
    - The right of the People to create Flash movies shall not be infringed. -

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