Welcome Guest [Log In] [Register]
Welcome to Brackenwood. We hope you enjoy your visit.


You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Sound control; Pause play and stop sounds
Topic Started: Mar 28 2006, 04:19 AM (232 Views)
juggleballz
Member Avatar
I'm loose, full of juice and ready for use!
This is confusing the life out of me.

Say i have a button that once clicked, an external Movie clip is loaded into flash.

This external movieclip is a media player, with play pause and stop buttons.

the sound plays automatically with the code..."attachsound" etc.

as the sound clip is not actually inside a movie clip and it playing straight from the library, is it possible to pause it, rewind it, or adjust the volume using a slider, or does it have to be placed in a movieclip?

if it is i wud be soooooooo grateful if someone could help me out.

thanks you guys.
Offline Profile Quote Post Goto Top
 
smoscar_01
Member Avatar
Mid-Level ActionScripter
hi juggz :lol: it can be done with the next lines:

Code:
 
snd= new Sound( _root );
snd.attachSound( "Soundtrack" );
snd.start();


and then controlling your sound with snd.stop();

Note remember to link your sound to ActionScript ;)
Offline Profile Quote Post Goto Top
 
juggleballz
Member Avatar
I'm loose, full of juice and ready for use!
thanks smoscar, i got that bit already.

im wondering if u can control the volume with a slider, also pause it... :huh:

cheers for helping dude
Offline Profile Quote Post Goto Top
 
smoscar_01
Member Avatar
Mid-Level ActionScripter
first add a button to your scene (this is going to be your volume slider) and add this code to it

Code:
 
on (press)
   startDrag ("", false, 0, 0, 0, -100);

on (release, releaseOutside)
   stopDrag ();


then you are gonna have to add a setVolume action like this

Code:
 

slider._y=130;
vol = slider._y - 100;
snd.setVolume(vol);


and thats going to do the trick ;)
Offline Profile Quote Post Goto Top
 
juggleballz
Member Avatar
I'm loose, full of juice and ready for use!
i also need it so when u press play, it plays the sound but ony once...

In other words, when i press play it plays the song, if i press play again, the song duplicates and u can hear two of the same song playing, and if i press it a 100 times, u can hear 100 songs playing, and thats not good.

plus can u pause it with simple code? and once pressing play allow it to play from that position again?


If this is impossible, what i can do is have a media player with a movieclip embedded in it with the sound in it....i dunno, media players are difficult.
Offline Profile Quote Post Goto Top
 
smoscar_01
Member Avatar
Mid-Level ActionScripter
Quote:
 
plus can u pause it with simple code? and once pressing play allow it to play from that position again?


yeah it can be easily done lets say that you have a var called pos wich is going to be the actual position when paused of the sound so lets say you have a pause button:

Code:
 
on (release){
  _root.pos = _root.snd.position / 1000;
  _root.snd.stop();
}


and then you need to have this at the play button

Code:
 
on (release){
   _root.snd.start(_root.pos);
}


so then when you 'pause' it you are really stoping it and recording the position value of the sound so when you play it again it can know where to start from ;)

Quote:
 
i also need it so when u press play, it plays the sound but ony once...


you can disable the play button once it is pressed and enable it only if stop or pause is pressed, something like this...

Code:
 
on (release){
 if (_root.playenable){
    _root.playenable = false;
    _root.snd.start();
  }
}


and at the stop button enable it again

Code:
 
on (release){
 if (!_root.playenable){
    _root.playenable = true;
    _root.snd.stop();
  }
}
Offline Profile Quote Post Goto Top
 
juggleballz
Member Avatar
I'm loose, full of juice and ready for use!
smoscar man! thankyou makes sense. Its quite logical!

How the hell do u remember that? I find it difficult remember what goes where etc.

Thnaks a million smoscar dude! hopefully will work but knowing me, I will be back here to annoy you for help once again lol. ;)

Cheers mate.

(smoscar for motm... :D ;) :lol: )
Offline Profile Quote Post Goto Top
 
smoscar_01
Member Avatar
Mid-Level ActionScripter
:lol:

I dont know all of them by heart what I do is write:

var myobject:Sound;
myobject.

and wait for the display list of properties and methods of each object, in this case of a Sound object but as soon as you type myobject: another display list of posible objects will appear for you ;)

Quote:
 
I will be back here to annoy you for help once again


Dont worry it isnt an annoyment :lol:
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Actionscript · Next Topic »
Add Reply