# Count number how many times button have been click

**URL:** https://forum.kirupa.com/t/count-number-how-many-times-button-have-been-click/56500
**Category:** Uncategorized
**Created:** [July 5, 2004, 10:16am UTC](https://forum.kirupa.com/t/count-number-how-many-times-button-have-been-click/56500 "2004-07-05T10:16:23Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Jins](https://avatars.discourse-cdn.com/v4/letter/j/9de053/32.png) [@Jins](https://forum.kirupa.com/u/Jins)
#### Post date: [July 5, 2004, 10:16am UTC](https://forum.kirupa.com/t/count-number-how-many-times-button-have-been-click/56500/1 "2004-07-05T10:16:23Z")

</div>

hi, how to count how many times the btn have been click. After counted the number of btn been click , according to the number , load the sound that match with the number of the btn been click.

i upload the fla zip file to here.anyone who know how to do it , plz reply me.thanks.

At the first frame :

```auto

Sound = new Sound();
Sound.attachSound("firstSound01.wav","secondSound02.wav");

At the btn's action:

```

on (release) {  
count++;  
trace(count);  
if (count == 1) {  
\_root.Sound.start();  
\_root.Sound.firstSound01.start();  
}  
if (count == 2) {  
\_root.Sound.start();  
\_root.Sound.secondSound02.start();  
}  
//if (count == 3) {  
// \_root.Sound.start();  
// \_root.Sound.thirdSound03.start();  
//}  
//if (count ==4){  
// \_root.Sound.start();  
// \_root.Sound.forthSound04.start();  
// count=""  
//}  
}

b’cos of the file is too big i can’t attach here,so i post the code here.With using these code, the sound come out when i click the btn is firstSound01.wav,the second time i click the btn the sound come out still firstSound01.wav.How to make it come out secondSound02.wav when i click the btn after first sound finish.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 5, 2004, 11:35am UTC](https://forum.kirupa.com/t/count-number-how-many-times-button-have-been-click/56500/2 "2004-07-05T11:35:29Z")

</div>

There are a few errors in your code. Try something like this:

```auto
//at the first frame
my_sound = new Sound(this);

//on the button
on (release) {
	count++;
	switch (count) {
	case 1 :
		id = "firstSound01.wav";
		break;
	case 2 :
		id = "secondSound02.wav";
		break;
	case 3 :
		id = "thirdSound03.wav";
		break;
	default :
		id = "forthSound04.wav";
	}
	_root.my_sound.attachSound(id);
	_root.my_sound.start(0, 1);
}

```

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 7, 2004, 2:22am UTC](https://forum.kirupa.com/t/count-number-how-many-times-button-have-been-click/56500/3 "2004-07-07T02:22:30Z")

</div>

hi, it doesnt work.what is the mean of “id”? i use ur code to do it but it didnt give me any respone.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 7, 2004, 3:04am UTC](https://forum.kirupa.com/t/count-number-how-many-times-button-have-been-click/56500/4 "2004-07-07T03:04:53Z")

</div>

Yes it works.  
\*id \* is a variable that controls which sound should play.  
Did you give the linkage names to each sound file?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 7, 2004, 9:21am UTC](https://forum.kirupa.com/t/count-number-how-many-times-button-have-been-click/56500/5 "2004-07-07T09:21:05Z")

</div>

> [@claudio](#):
>
> Yes it works.  
> \*id \*is a variable that controls which sound should play.  
> Did you give the linkage names to each sound file?

wat is the linkage name u mean??izzit where i should put in the first frame ?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 7, 2004, 1:32pm UTC](https://forum.kirupa.com/t/count-number-how-many-times-button-have-been-click/56500/6 "2004-07-07T13:32:18Z")

</div>

To work with attached sounds you must to give a linkage name to the sound file in the library, so you can reference it.  
Right click the sound file in the library, linkage, and check the export for actionscript option.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 8, 2004, 2:18am UTC](https://forum.kirupa.com/t/count-number-how-many-times-button-have-been-click/56500/7 "2004-07-08T02:18:23Z")

</div>

hi,the linkage which u told me i ady done when i import the sound file into the flash library.  
so wat is the problem??is what i type for the sound fine name correct??

```auto
 
on(press){ 
  switch(mycounter){ 
	case 0: 
		id = "firstSound01.wav";
		break; 
	case 1: 
		id = "secondSound02.wav";
		break; 
	case 2: 
		id = "thirdSound03.wav";
		break; 
	 default: 
		id = "fourthSound04.wav";
		break; 
  } 
  mycounter++ 
}
 

```

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 8, 2004, 2:47am UTC](https://forum.kirupa.com/t/count-number-how-many-times-button-have-been-click/56500/8 "2004-07-08T02:47:16Z")

</div>

What about the rest of the code i posted before?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 8, 2004, 7:15am UTC](https://forum.kirupa.com/t/count-number-how-many-times-button-have-been-click/56500/9 "2004-07-08T07:15:38Z")

</div>

hi, i dunno what the code u post for the rest , but anyway thanks for helping , i donw it already .

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 8, 2004, 11:57am UTC](https://forum.kirupa.com/t/count-number-how-many-times-button-have-been-click/56500/10 "2004-07-08T11:57:01Z")

</div>

> [@Jins](#):
>
> hi, i dunno what the code u post for the rest , but anyway thanks for helping , i donw it already .

Did you pay attention to the code i posted before? The one you just posted is not the exact one i posted, so its never going to work.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 9, 2004, 1:07am UTC](https://forum.kirupa.com/t/count-number-how-many-times-button-have-been-click/56500/11 "2004-07-09T01:07:18Z")

</div>

sorry, cos i make changes ady.anyway thanks i done it.
