On click do this

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.

Never mind… silly me
I understand what you mean now

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

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

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

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

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

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

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

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…

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

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

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

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;
		}
	}
};

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 :frowning:

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