A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [F8] play pause sound not working

Hybrid View

  1. #1
    Junior Member
    Join Date
    Feb 2001
    Posts
    2

    [F8] play pause sound not working

    Hi there,

    I am a newby to actionscript, currently learning the code.
    I am in a bit of a fix as I need to complete a job by Monday.

    I got this code from O'Reilly's web site. The problem is the sound does not pause at all. I have added the linkage.

    Your help/guidance will be greatly appreciated.

    Thank you in advance.


    Code:
    // Attach a push button from the Library. You must first drag a push button from the
    // Components panel to the Stage to create the Library symbol.
    this.attachMovie("FPushButtonSymbol", "myPushButton", 1);
    
    // Create a sound holder movie clip.
    this.createEmptyMovieClip("soundHolder_mc", 2);
    
    // Create the Sound object.
    mySound_sound = new Sound(soundHolder_mc);
    
    // Attach the sound from the Library. You must have a sound with the linkage
    // identifier of MySoundSymbol for this to work.
    mySound_sound.attachSound("MySoundSymbol");
    
    // Define two callback functions. One resumes the sound, and the other pauses the
    // sound. When each is called, it toggles the click handler for the push button to
    // the other function.
    function resumeSound (  ) {
      mySound_sound.resume(  );
      myPushButton.setClickHandler("pauseSound");
      myPushButton.setLabel("Pause Sound");
    }
    
    function pauseSound (  ) {
      mySound_sound.pause(  );
      myPushButton.setClickHandler("resumeSound");
      myPushButton.setLabel("Resume Sound");
    }
    
    // Define the initial click handler and label for the push button.
    myPushButton.setClickHandler("pauseSound");
    myPushButton.setLabel("Pause Sound");
    
    // Tell the sound to start.
    mySound_sound.start(  );
    Image7

  2. #2
    Junior Member
    Join Date
    Feb 2001
    Posts
    2
    I found the problem. I missed some important code from O'Reilly's site

    Sound.prototype.pause = function ( ) {
    // Get the current position and then stop the sound.
    this.pauseTime = this.position;
    this.stop( );
    };

    Sound.prototype.resume = function ( ) {
    // Start the sound at the point at which it was previously stopped.
    this.start(this.pauseTime/1000);
    };

    I added it and it works perfectly.

    2ND QUESTION...

    Can this code be used/modified to play pause mp3's called externally instead of embedding them?
    Image7

  3. #3
    Senior Member layerburn's Avatar
    Join Date
    Jul 2006
    Location
    USA
    Posts
    542
    This should be really simple. Here is the script you'll need. Your mp3s don't need to be in your library, just make sure they're in the same folder as your project.

    Code:
    //set up variable on first frame of project
    var my_sound:Sound = new Sound();
    
    
    //put on frame you wish sound to start
    //change soundname to the name of your file, must have extension on there in quotes
    my_sound.loadSound("soundname.mp3", false);
    
    //script you would use on your pause button to stop the sound
    on(release) {my_sound.stop();}
    
    //script to make the audio play from where it was paused
    //goes on your audio play button
    on(release) {my_sound.start(my_sound.position/1000);}
    This is your brain. This is your brain on script.

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