PDA

View Full Version : How do I detect which button has been pressed?



yorkshirepuddin
November 29th, 2002, 10:11 PM
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?

lostinbeta
November 29th, 2002, 11:16 PM
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");
}
};

lostinbeta
November 29th, 2002, 11:28 PM
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";
};

yorkshirepuddin
November 30th, 2002, 10:08 AM
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?

yorkshirepuddin
November 30th, 2002, 10:18 AM
I actually just checked another board I posted to (don't tell anyone, I'm a faithful Kirupa girl I promise :P ) 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.

yorkshirepuddin
November 30th, 2002, 11:57 AM
Not to worry anyone, I figured it out. :) I'm a happy Yorkie this morning!

lostinbeta
November 30th, 2002, 06:31 PM
LOL, congrats! :)