# How do I detect which button has been pressed?

**URL:** <https://forum.kirupa.com/t/how-do-i-detect-which-button-has-been-pressed/8877>\
**Category:** flash\
**Created:** [November 30, 2002, 3:11am UTC](https://forum.kirupa.com/t/how-do-i-detect-which-button-has-been-pressed/8877 "2002-11-30T03:11:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![yorkshirepuddin](https://avatars.discourse-cdn.com/v4/letter/y/aeb1de/32.png) [@yorkshirepuddin](https://forum.kirupa.com/u/yorkshirepuddin)\
**Post date:** [November 30, 2002, 3:11am UTC](https://forum.kirupa.com/t/how-do-i-detect-which-button-has-been-pressed/8877/1 "2002-11-30T03:11:01Z")

</div>

I’ve played with this thing forever, here’s my script:

if (\_root.navigation.whois.onPress) {  
loadMovie(“content.swf”, \_root.contentarea);  
\_root.targetx = 140;  
\_root.slide.gotoAndPlay(“move”);  
} else if (\_root.navigation.cranium.onPress) {  
loadMovie(“content.swf”, “\_root.contentarea”);  
\_root.targetx = -280;  
\_root.slide.gotoAndPlay = “move”;  
}

It doesn’t seem to read the ‘else if’ statement, it automatically sets the .x to that of the ‘if’ statement (i.e. 140 instead of -280 ).

Where am I going wrong?

---

<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 30, 2002, 4:16am UTC](https://forum.kirupa.com/t/how-do-i-detect-which-button-has-been-pressed/8877/2 "2002-11-30T04:16:12Z")

</div>

onPress is used to define a function for when a movie clip is pressed… not to tell if it has been pressed.

The best code I can think of would be something like this… (keep in mind my mind is kinda fluky tonight, so I am not sure if this works or not)

```auto
_root.navigation.whois.onPress = function() {
	_root.trip = 1;
	checkTrip();
};
_root.navigation.cranium.onPress = function() {
	_root.trip = 2;
	checkTrip();
};
checkTrip = function () {
	if (_root.trip == 1) {
		trace("whois pressed");
	} else if (_root.trip == 2) {
		trace("cranium pressed");
	}
};

```

---

<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 30, 2002, 4:28am UTC](https://forum.kirupa.com/t/how-do-i-detect-which-button-has-been-pressed/8877/3 "2002-11-30T04:28:13Z")

</div>

I am thinking though… that if you are going to do that, then you might as well just do…

```auto
_root.navigation.whois.onPress = function() {
	loadMovie("content.swf", _root.contentarea);
	_root.targetx = 140;
	_root.slide.gotoAndPlay("move");
};
_root.navigation.cranium.onPress = function() {
	loadMovie("content.swf", "_root.contentarea");
	_root.targetx = -280;
	_root.slide.gotoAndPlay = "move";
};

```

---

<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 30, 2002, 3:08pm UTC](https://forum.kirupa.com/t/how-do-i-detect-which-button-has-been-pressed/8877/4 "2002-11-30T15:08:29Z")

</div>

I realised the .onPress thing at 1.00 am and gave up! 🙂

You’re second option makes sense and in fact, that’s what I originally had. However, this situation is different.

On first press of any button, the user goes to an animation first (will eventually be a preloader I guess), at the end of this animation, it needs to know which button was pressed to activate the animation so that it knows which part of the loaded .swf to go to.

After first press, the nav goes to a new label and has the regular functions. Make sense?

---

<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 30, 2002, 3:18pm UTC](https://forum.kirupa.com/t/how-do-i-detect-which-button-has-been-pressed/8877/5 "2002-11-30T15:18:12Z")

</div>

I actually just checked another board I posted to (don’t tell anyone, I’m a faithful Kirupa girl I promise 😛 ) and they said I need to set a variable to determine which one was pressed.

Mmm… next question … how?

Time to look up a little more about variables.

---

<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 30, 2002, 4:57pm UTC](https://forum.kirupa.com/t/how-do-i-detect-which-button-has-been-pressed/8877/6 "2002-11-30T16:57:23Z")

</div>

Not to worry anyone, I figured it out. 🙂 I’m a happy Yorkie this morning!

---

<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 30, 2002, 11:31pm UTC](https://forum.kirupa.com/t/how-do-i-detect-which-button-has-been-pressed/8877/7 "2002-11-30T23:31:13Z")

</div>

LOL, congrats! 🙂
