How do I detect which button has been pressed?

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?

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)

_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");
	}
};

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

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

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

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?

I actually just checked another board I posted to (don’t tell anyone, I’m a faithful Kirupa girl I promise :stuck_out_tongue: ) 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.

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

LOL, congrats! :slight_smile: