Play / Stop

  • Jako
  • Banned
  • Banned
  • Jako
  • Posts: 227

Post 3+ Months Ago

I want to have a play button that when released loads the music from a site, also I don't want you to be able to click on it again and play the music over the first one so you can hear the repeats...

Also what is the coding for the stop button of this


Thanks.
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13504
  • Loc: Florida

Post 3+ Months Ago

Provided you have a play button with the instance name playBut & a stop button with the instance name stopBut in your main timeline, you can build somthing from this example :D
This is setup to load and play a streaming sound disabling the play button once it has been pressed, the play button is re-enabled once either the stop button is pressed or the sound is done playing.
Code: [ Select ]
music = new Sound();
music.onSoundComplete = function() {
    playBut.enabled = true;
}
playBut.onPress = function(){
    music.loadSound("freedom.mp3",true);
    playBut.enabled = false;
}
stopBut.onPress = function(){
    music.stop();
    playBut.enabled = true;
}
  1. music = new Sound();
  2. music.onSoundComplete = function() {
  3.     playBut.enabled = true;
  4. }
  5. playBut.onPress = function(){
  6.     music.loadSound("freedom.mp3",true);
  7.     playBut.enabled = false;
  8. }
  9. stopBut.onPress = function(){
  10.     music.stop();
  11.     playBut.enabled = true;
  12. }

This is a very basic example, i'm sure when Lostinbeta catches this topic he will have this thing doing backflips over molten pools of lava :lol:
  • Jako
  • Banned
  • Banned
  • Jako
  • Posts: 227

Post 3+ Months Ago

Code: [ Select ]
music = new Sound();
music.onSoundComplete = function() {
    playBut.enabled = true;
}
playBut.onPress = function(){
    music.loadSound("http://jako.us/term.mp3",true);
    playBut.enabled = false;
}
  1. music = new Sound();
  2. music.onSoundComplete = function() {
  3.     playBut.enabled = true;
  4. }
  5. playBut.onPress = function(){
  6.     music.loadSound("http://jako.us/term.mp3",true);
  7.     playBut.enabled = false;
  8. }


That is what i put for the play button


Code: [ Select ]
stopBut.onPress = function(){
    music.stop();
    playBut.enabled = true;
}
  1. stopBut.onPress = function(){
  2.     music.stop();
  3.     playBut.enabled = true;
  4. }


And this is what I put for the stop button

Cause when I do it like that while also naming the buttons as you said, I am getting some errors. Anything else wrong w/ the code I just pasted above?
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13504
  • Loc: Florida

Post 3+ Months Ago

Code is fine, I just pasted your code into FlashMX placed the buttons in the same timeline and everything tested perfect.

Are your buttons inside a movieclip ?
Are you putting this AS on the buttons themselves ?
Are you using the buttons from flashs form components library?
What errors are you getting ?
  • Jako
  • Banned
  • Banned
  • Jako
  • Posts: 227

Post 3+ Months Ago

Am I supposed to paste the AS on the layers themselves, or the individual buttons.

When I paste them on the corresponding buttons I get this error
Code: [ Select ]
**Error** Scene=Scene 1, layer=Layer 2, frame=1:Line 1: Statement must appear within on handler
   music = new Sound();

**Error** Scene=Scene 1, layer=Layer 2, frame=1:Line 2: Statement must appear within on handler
   music.onSoundComplete = function() {

**Error** Scene=Scene 1, layer=Layer 2, frame=1:Line 5: Statement must appear within on handler
   playBut.onPress = function(){

Total ActionScript Errors: 3      Reported Errors: 3
  1. **Error** Scene=Scene 1, layer=Layer 2, frame=1:Line 1: Statement must appear within on handler
  2.    music = new Sound();
  3. **Error** Scene=Scene 1, layer=Layer 2, frame=1:Line 2: Statement must appear within on handler
  4.    music.onSoundComplete = function() {
  5. **Error** Scene=Scene 1, layer=Layer 2, frame=1:Line 5: Statement must appear within on handler
  6.    playBut.onPress = function(){
  7. Total ActionScript Errors: 3      Reported Errors: 3

When I post them on the frames for each button, I get no errors, but the sound does not play.
  • Jako
  • Banned
  • Banned
  • Jako
  • Posts: 227

Post 3+ Months Ago

Also, if possible and I think it is. Can I have the song play as a stream, I think that's what you call it. So instead of waiting for the whole song to download, it can just play as much as it has already downloaded.
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13504
  • Loc: Florida

Post 3+ Months Ago

The actions go in the main timeline (the only one you have if you start a new movie)

either drag flashs component buttons onto the stage or create your own and place them on the stage.

Give theese buttons the instance names playBut & stopBut.

The line music.loadSound("song.mp3",true); controls streaming with the true/false at the end. true for streaming, false to load song completely before playing.

checkout the links Unflux refers to here, http://www.ozzu.com/flash-forum/req-flash-mp3-player-t23501.html
Theese are more advanced examples and there is an fla to study.
  • Jako
  • Banned
  • Banned
  • Jako
  • Posts: 227

Post 3+ Months Ago

Thanks for all your help joe

I got it working, but with one error still, but it works

Code: [ Select ]
**Error** Scene=Scene 1, layer=Layer 2, frame=1:Line 2: Wrong number of parameters; loadMovie requires between 2 and 3.
       loadMovie("http://jako.us/term.mp3");

Total ActionScript Errors: 1      Reported Errors: 1
  1. **Error** Scene=Scene 1, layer=Layer 2, frame=1:Line 2: Wrong number of parameters; loadMovie requires between 2 and 3.
  2.        loadMovie("http://jako.us/term.mp3");
  3. Total ActionScript Errors: 1      Reported Errors: 1


One last thing, lol. What is the code to have like a forward and a back, to cycle through tracks.
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13504
  • Loc: Florida

Post 3+ Months Ago

loadMovie("http://jako.us/term.mp3");

needs to be,

loadMovie("http://jako.us/term.mp3",true); for streaming, loadMovie("http://jako.us/term.mp3", false); for no streaming.

You really should check this fla out, http://www.ozzu.com/flash-forum/req-flash-mp3-player-t23501.html has everything your lookin for to learn :wink:
  • lvchang
  • Novice
  • Novice
  • User avatar
  • Posts: 34
  • Loc: malaysia

Post 3+ Months Ago

I also have problem with that!

since i can't link it from one scene to the other!

i try to write get url and get the swf!

but.......don't know what to say!

Post Information

  • Total Posts in this topic: 10 posts
  • Users browsing this forum: No registered users and 28 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.