Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 03-18-2005, 07:54 AM   #1
ConanBM
Registered User
 
Join Date: Jan 2005
Posts: 5
Default play and pause mp3 sound with one button

Hi, I am an absolute beginner in Flash.. and I’m trying to make a.script for one button witch will play and pause mp3 sound from my library. Can someone help?
BM
ConanBM is offline   Reply With Quote
Old 03-18-2005, 12:55 PM   #2
tGP
-->
 
tGP's Avatar
 
Join Date: Sep 2004
Location: Newport Beach, CA
Posts: 346
Default

this is using loadSound, where you can place the mp3 outside of your movie, and it will load stream it, change loadSound() to attachSound() if you want it to remain in the library...
ActionScript Code:
this.createEmptyMovieClip("sound_mc", 10); music = new Sound(sound_mc); music.loadSound("test.mp3", true); music.start(); active_button = "play"; // pause button pause_button_mc.onRelease = function() {     if (active_button == "play") {         pause_resume = music.position;         music.stop();         active_button = "pause";     } } pause_button_mc.onRollOver = function() {     this._alpha = 50; } pause_button_mc.onRollOut = function() {     this._alpha = 100; } // play button play_button_mc.onRelease = function() {     if (active_button == "pause") {         music.start(pause_resume / 1000);         active_button = "play";     } } play_button_mc.onRollOver = function() {     this._alpha = 50; } play_button_mc.onRollOut = function() {     this._alpha = 100; }

be sure that you are using movieclips, not true "flash buttons" for the buttons, in this case.... just convert your button to a movieclip symbol, and give it an instance name of play_button_mc, and pause_button_mc...

also, make a new layer on the root (main) timeline, and place all this code in an empty keyframe...

hope this helps...

cheers
j
tGP is offline   Reply With Quote
Old 10-10-2005, 10:47 AM   #3
tayfun
Registered User
 
Join Date: Sep 2004
Posts: 3
Default dont really works!

hey there...so its not really working...i can pause the music, but it wont start again! could it be, that the script isn correct?
anyone knows`?


tayfun
tayfun is offline   Reply With Quote
Old 12-04-2005, 01:49 PM   #4
Suicidal.Banana
Registered User
 
Join Date: Nov 2005
Posts: 52
Default

Quote:
Originally Posted by tGP
ActionScript Code:
this.createEmptyMovieClip("sound_mc", 10); music = new Sound(sound_mc); music.loadSound("test.mp3", true); music.start(); .... Made shorter for quoting reasons .... play_button_mc.onRollOut = function() {     this._alpha = 100; }

be sure that you are using movieclips, not true "flash buttons" for the buttons, in this case.... just convert your button to a movieclip symbol, and give it an instance name of play_button_mc, and pause_button_mc...

also, make a new layer on the root (main) timeline, and place all this code in an empty keyframe...

hope this helps...

cheers
j
Very nice thx, that pause method also helped me out alot (though ive made the two buttons in one mc and using a dynamic path to the to-pause-mc)
Suicidal.Banana is offline   Reply With Quote
Old 03-16-2011, 04:15 PM   #5
IMD
Registered User
 
Join Date: Mar 2011
Posts: 13
Default Can i use that code for more than one audio?

I have three mp3 files in my folder and one plays after the other. Each on is loaded in a mc that i created myself.

I used your code to play and pause the sound... but it only works with the sound you load just before the buttons code.

this.createEmptyMovieClip("sound_mc", 10);

music = new Sound(sound_mc);
music.loadSound("test.mp3", true);

music.start();

So when i try to play and pause my sound files (3, which ever is playing in that moment) it doesn't work. Could it be because each one loads in different mc?
Could you help me?
Thank you
IMD is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:34 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.