Play, pause, stop

Hi, this is probably a dumb question as always, and I did search for it this time, but couldn’t find what i was looking for

I took the tutorial on playing a sound file, but I want to know how to pause it, and stop it, eventually i want to do next and previous song buttons, but im not worried about those 2 for now.

This is the code I have
[AS]on (release) {
Finchsound = new Sound(this);
Finchsound.attachSound(“Finch3”);
Finchsound.start(0, 99);
}[/AS]

Finchsound.pause doesnt exist, so what would i use as an alternative, and also finchsound.stop didnt work

finally, if you click play multiple times it just plays the song again, so you have a ton of overlapping songs.

any help would be great

thanks a lot

you can use a variable. something like


// create the variable in the timeline
status = "stopped";
// play button
on (release) {
	if (status == "stopped") {
		Finchsound = new Sound(this);
		Finchsound.attachSound("Finch3");
		Finchsound.start(0, 99);
		status = "playing";
	} else if (status == "paused") {
		Finchsound.start(pausedat, 99);
		status = "playing";
	}
}
// pause button
on (release) {
	if (status == "playing") {
		pausedat = Finchsound.position;
		status = "paused";
	}
}
// stop button
on (release) {
	if (status == "playing") {
		Finchsound.stop();
		status = "stopped";
	}
}

i didn’t test the script but at least that’s the idea =)

hey kax, thanks a lot for the reply
however… i don’t think i did it right
i would attatch a .fla but its way too big cuz i used a full song and i dont wanna search for a small loop
the song wont start and the output window produces
[AS]Scene=Scene 1, Layer=Layer 1, Frame=1: Line 1: Statement block must be terminated by ‘}’
on (release) {

Scene=Scene 1, Layer=Layer 1, Frame=1: Line 10: Syntax error.
}
[/AS]
not entirely sure what to do about that
all i have on the main timeline is - status = “stopped”;
do i need to do like an enterframe thing? if i do can u explain it because i am thoroughly confused

im sorry for all the dumb questions…

:stunned:
in theory … the script seems to be fine :slight_smile:

why don’t you delete the sound from the library and attach your fla … ??

alright… why didnt i think of that?

maybe i should attatch the .fla… duh

maybe i should attatch the .fla… duh

good idea :stuck_out_tongue: :wink:

ok … sorry for the delay :-\

i changed all the scripts to the timeline … it’s easier to edit/modify it that way :slight_smile:

no problem on the delay, i appreciate that u did that for me at all
thats really cool of u, the good thing is that most of the code makes sense to me.
I’m gonna fool around with it to see if i can make it play again when u push the pause button for a second time but I’m not worried about that too much.
thank u so much!

woohoo!
i did it! on my own!
score
thanks again kax :love:

no problem =)

I’m gonna fool around with it to see if i can make it play again when u push the pause button for a second time but I’m not worried about that too much.

why am i doing all of your work!!? :stuck_out_tongue:

pause_btn.onRelease = function() {
	if (songstatus == "playing") {
		pausedat = Finchsound.position/1000;
		Finchsound.stop();
		songstatus = "paused";
	} else if (songstatus == "paused") {
		Finchsound.start(pausedat, 99);
		songstatus = "playing";
	}
}

u didnt read the post after that did you?
cuz i figured it out on my own:beam:
but thank u again, thats cleaner than mine

good for you! =)

[size=1]note to kax. there’s something called reload[/size] :stuck_out_tongue:

by the way … i just realized that i added a few useless lines in the play_btn

play_btn.onRelease = function() {
	if (songstatus == "stopped") {
		Finchsound = new Sound();
		Finchsound.attachSound("Finch3");
		Finchsound.start(0, 99);
		songstatus = "playing";
	} else if (songstatus == "paused") {
		Finchsound.start(pausedat, 99);
		songstatus = "playing";
	}
}

i realized that as well!
WOW!!
I might finally be gettin the hang of this stuff…
ok so i still cant make my own stuff for crap
but im startin to understand how stuff works

thank u!

i realized that as well!
WOW!!
I might finally be gettin the hang of this stuff…

finally :sigh:. it was about time :stuck_out_tongue: :wink: [size=1]just kidding[/size]

awwwww
how sweet
come on tho, ive only been doin AS for about a month now
and im an incredibly slow learner due to the fact that im really stupid
so i think im doin alright

and you think that i learnt everything i know in a month? :sigh:

i learn something new every day! and i can assure that i will never stop learning something each day :slight_smile:

so you just keep practicing :wink:

Oh I will
I wanna be amazing like everyone here… shh… yah… thats gonna happen

shh… yah… thats gonna happen

eventually … :stuck_out_tongue:

[size=1]ps. you know i’m kidding again :wink: =)[/size]