# On click do this

**URL:** <https://forum.kirupa.com/t/on-click-do-this/34371>\
**Category:** Uncategorized\
**Created:** [November 1, 2003, 2:53am UTC](https://forum.kirupa.com/t/on-click-do-this/34371 "2003-11-01T02:53:57Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![macneilslt](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@macneilslt](https://forum.kirupa.com/u/macneilslt)\
**Post date:** [November 1, 2003, 2:53am UTC](https://forum.kirupa.com/t/on-click-do-this/34371/1 "2003-11-01T02:53:57Z")

</div>

i’m making a simple game in which you shoot a target by clicking on it with the mouse, but i want there to be a limited number of shots,

so i have a dynamic text box with a var of bullets, i’m trying to write some AS so that when ever the user clicks anywhere inside of the movie, it subtracts one from the number of bullets left.

---

<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:** [November 1, 2003, 3:17am UTC](https://forum.kirupa.com/t/on-click-do-this/34371/2 "2003-11-01T03:17:45Z")

</div>

Never mind… silly me  
I understand what you mean now

---

<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:** [November 1, 2003, 3:19am UTC](https://forum.kirupa.com/t/on-click-do-this/34371/3 "2003-11-01T03:19:16Z")

</div>

you’re gonna adjust the code above to use onMousedown  
sorry for the mixup

someListener = new Object();  
someListener.onMouseDown = function () { … };  
Mouse.addListener(someListener);

---

<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:** [November 1, 2003, 3:33am UTC](https://forum.kirupa.com/t/on-click-do-this/34371/4 "2003-11-01T03:33:18Z")

</div>

okay, this is a basic example of what i’m trying to accomplish, i think this how to go about what i want.

---

<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:** [November 1, 2003, 3:42am UTC](https://forum.kirupa.com/t/on-click-do-this/34371/5 "2003-11-01T03:42:06Z")

</div>

```auto
this.onMouseDown = function() {
	--bullets;
};

```

---

<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:** [November 1, 2003, 3:46am UTC](https://forum.kirupa.com/t/on-click-do-this/34371/6 "2003-11-01T03:46:28Z")

</div>

yeah… and you will want to stop when it reaches zero, otherwise you’ll get into neg numbers

---

<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:** [November 1, 2003, 3:48am UTC](https://forum.kirupa.com/t/on-click-do-this/34371/7 "2003-11-01T03:48:03Z")

</div>

i was wondering one other thing, would something like this work,  
if i had a mc target, instead of a button…

onClipEvent(enterFrame) {  
if(this.hitTest(\_root.\_xmouse,\_root.\_ymouse))  
function(){  
bullets-=1;  
}  
}

or, a hitTest on mouse down ? bah, i’m confusing my self

---

<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:** [November 1, 2003, 3:50am UTC](https://forum.kirupa.com/t/on-click-do-this/34371/8 "2003-11-01T03:50:21Z")

</div>

What, you want the bullets value to be subtracted only when the mouse is over the target?

---

<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:** [November 1, 2003, 3:53am UTC](https://forum.kirupa.com/t/on-click-do-this/34371/9 "2003-11-01T03:53:13Z")

</div>

only when the mouse is pressed on the target, like if you click on the target mc, it would subtract a bullet, and play frame 2, where it has an x on it, then dissapear…

---

<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:** [November 1, 2003, 4:04am UTC](https://forum.kirupa.com/t/on-click-do-this/34371/10 "2003-11-01T04:04:27Z")

</div>

okay, i think i almost understand  
i posted a revised fla, when you click the target you lose a bullet, and gain a point, but even if you click something out side of the target, you still gain a point

---

<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:** [November 1, 2003, 4:05am UTC](https://forum.kirupa.com/t/on-click-do-this/34371/11 "2003-11-01T04:05:57Z")

</div>

```auto
target.onPress = function() {
	if (bullets != 0) --bullets
};

```

---

<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:** [November 1, 2003, 4:14am UTC](https://forum.kirupa.com/t/on-click-do-this/34371/12 "2003-11-01T04:14:28Z")

</div>

Ah i see what you trying to do… erase the code on your ctarget mc. Place this code on the timeline:

```auto
var bullets = 10;
var score = 0;
this.onMouseDown = function() {
	if (bullets != 0) {
		if (ctarget.hitTest(_xmouse, _ymouse, false)) {
			--bullets;
			++score;
			ctarget.gotoAndPlay(2);
		} else {
			--bullets;
		}
	}
};

```

---

<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:** [November 1, 2003, 7:58am UTC](https://forum.kirupa.com/t/on-click-do-this/34371/13 "2003-11-01T07:58:03Z")

</div>

var bullets = 10;  
var score = 0;  
this.onMouseDown = function() {  
if (bullets != 0) {  
if ([“ctarget”+i].hitTest(\_xmouse, \_ymouse, false)) {  
–bullets;  
++score;  
[“ctarget”+i].gotoAndPlay(2);  
} else {  
–bullets;  
}  
}  
};

numctarget = 4;  
for (i=2; i\<=numctarget; i++) {  
ctarget.duplicateMovieClip(“ctarget”+i, i+100);  
}

that is the AS i tried to use to duplicate the target, so there is more than one on the screen, how ever it no longer works ☹

---

<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:** [November 1, 2003, 9:48am UTC](https://forum.kirupa.com/t/on-click-do-this/34371/14 "2003-11-01T09:48:14Z")

</div>

[http://www.kirupaforum.com/forums/showthread.php?s=&threadid=12082](http://www.kirupaforum.com/forums/showthread.php?s=&threadid=12082)
