4 Replies Latest reply on Oct 18, 2008 4:50 PM by Malborojones

    How to load play and pause from library?

    shintashi Level 1
      I've tried all kinds of methods, like attachsound, loadsound, load audio, and nil seems to work. I have a single music file in my library. How do I pull it from library, play when I push a play button, pause when I push a pause button, and resume (not start over) when I push the play button again?
        • 1. Re: How to load play and pause from library?
          kglad Adobe Community Professional & MVP
          1. assign it a linkage id.
          2. create a sound instance using the "new" constructor
          3. apply the attachSound method to your sound instance using your linkage id
          4. apply the start() method to that sound instance in your play button handler to make it play and stop() method to make it stop.
          • 2. Re: How to load play and pause from library?
            shintashi Level 1
            whoa, I completely spaced the linkage - sorry about that.

            but the 2nd step "create a sound instance using the "new" constructor" - I've actually never done this before. does it look like this stuff? I didn't quite know what to do with it (having no linkage probably didn't help)

            • 3. Re: How to load play and pause from library?
              Malborojones
              use my_song as the linkage and "my_song" in the script an it should work
              like this:

              var music:Sound = new Sound();
              music.attachSound("my_song", true);
              music.start();

              if you want the music to loop, in the brackets of start(), put: (0,10)
              it looks like - start(0,10),
              the 0 indicates the offset meaning how long until it starts to play, the 10 indicates the amount of times looped, in this case 10!!

              hope i helped :)
              • 4. Re: How to load play and pause from library?
                Malborojones Level 1
                p.s.if you want a button to control the playback...

                First do as you already have with my previous code,
                Create a button with an instance name e.g. play_btn.

                Go back to the main frame, open actions add this:

                play_btn.onPress = function(){
                music.start();
                }

                get rid of the previous music.start();

                your code will be:

                stop();
                //load sound
                var music:Sound = new Sound();
                music.attachSound("my_song", true);
                //play sound
                play_btn.onPress = function(){
                music.start();
                }

                I'm quite new to flash but I'm getting better!

                Glad to help =]