onMousePress

im trying to make a button play an animation after u click on a button but it doesnt seem to be working. i also want the button to stay a certain color after u click on it. can anyone help me out? thanx! i saved it as flash 5 (for another user to check out), but i do have mx.

on (rollOver) {
with (hello) {
gotoAndPlay(2);
}
}
on (rollOut) {
with (hello) {
gotoAndStop(1);
}
}
on (press) {
with (hello) {
gotoAndPlay(20);
}
}

on (rollOver) {
with (imstuck) {
gotoAndPlay(2);
}
}
on (rollOut) {
with (imstuck) {
gotoAndStop(1);
}
}
on (press) {
with (imstuck) {
gotoAndPlay(10);
}
}

Ok… the with statements are correct… BUT… there is an easier way.

Also, instead of using button symbols, since you use MX you can use movie clips as buttons.

Covert a shape into a movie clip. Double click the movie to for editing. Insert a keyframe on Frame 2(and change the look of the object… like the color or something). Insert a stop() action on both frame 1 and frame 2.

Go back to the main timeline and right click on your movie clip symbol and open the actions panel.

Use these actions…

onClipEvent (load) {
	trigger = 1;
}
on (rollOver) {
	_root.imstuck.play();
}
on (rollOut) {
	_root.imstuck.gotoAndStop(1);
}
on (press) {
	_root.imstuck.gotoAndPlay(10);
	if (trigger == 1) {
		this.gotoAndStop(2);
		trigger = 2;
	} else {
		this.gotoAndStop(1);
		trigger = 1;
	}
}

This will set a variable called “trigger” to 1, and when you press, if the trigger variable is one, it stops at the movie clips (the one that is acting like a button) frame 2 (which is the frame that has the different colored object), then it sets the trigger variable to 2. If you click the button again, since the trigger variable is not equal to one, it will stop at the first frame of the button movie clip, then set the trigger variable back to one so that when you click it again it will go back to frame 2. If you don’t want this to happen, just remove the else {} statement.

Repeat the process for the other button.

NOTE: Movie clips can only use on handlers in MX.

thanx. i tried that but i got a whole bunch of errors saying i could only use it on buttons?? can u actually modify this file? like what i want happening is when the user clicks on the button, it stays on the Over state (including the remote rollover)until u click on another button, the button clicked on before reverts back to the Normal state. i know it sounds a lil confusing but if can check out my file and modify it a lil then maybe ill understand whats going on! thanks!

It is giving you those errors because you are saving as Flash 5. In your publish settings set it back to Flash 6 and it should all be good. Since Flash 5 doesn’t support MC buttons it won’t work to export it like that.

Save the animation in a movieclip…give it an instance name of say “animation”.

Also, be sure that the first frame of the animation has a stop(); function in it, and the last frame has a gotoAndPlay(2); function.

Then on your button just put…

on (rollOver) {
_root.animation.gotoAndPlay(2);
}
on (rollOut) {
_root.animation.gotoAndPlay(1);
}

I covered that already, the problem was that he was getting an error statement saying on handlers can only be used on buttons. That is because he had his publish settings set to publish at Flash 5 when it should be at Flash 6.

If you want to set up the example of using triggers to lock the button in place once it is clicked, be my guest :beam:

great! thanks beta! i have a few more questions.

  1. Is there a way to make the grafx stay in place too (after clicking on the button) the button changes color (good) but the graphic beside it doesnt show up (it disappears after u move the mouse away from the button.) i decided not to have an animation play when u move your mouse over the mc. (instead, i just want like a plain text to show up beside the button, when u move your mouse over the button) how should the code be like?

  2. i also noticed when i hovered the mouse over the movie clip, it wouldnt change colors unless i clicked on it. is there a way to make it change colors when u mouseover on the mc or is it only possible with buttons?

  3. last question, i promise! for example, when i click on “button 1” (it changes to the Over state) and then i click on “button 2”, how do i make “button 1” automatically revert back to its original state?

hope u can keep the code nice and simple for me to understand! thanks! :smirk:

Alright man… it is 2:30am and I am not sure if I fully got what you were trying to do. I think I did.

I am extremely tired… I whipped up this quick .fla file for you. I commented the code and everything so hopefully it will be easy to understand.

I have a really strong feeling I took the hard way around this, but I am not really concentrating… as long as it works ya know…lol.

Check the attachment… (the code is on the grey and black buttons, just right click them and open the actions panel to see the AS).

I sure hope this was what you wanted :-\

Yup, thats what im talkin about! 99% of what i wanted! :beam:

Are you able to make the PSONE TEXT (beside the grey box) appear when u mouseover on the box too? cuz right now, it only shows up after u click on it. where would i add the getURL code after the user clicks on the button?

heres a screenshot of what im talking about.

woah, and u did it in Expert mode. thats amazing! im still using Normal mode.

thanks alot!

Yeah, I actually had it working like that with a different script, but I found it to be real confusing to see it on rollOver but to have to click it to keep it there. It would be much easier to just have them click for the extra info.

And yes, I always use Expert Mode. I always used Expert Mode. That way I could learn from my mistakes :wink:

i actually kinda wanted it like that cause ill be using symbols (not text) on the boxes and the description on the side will appear on mouseover. (like when i was using the With code before)thats why i want to see it on rollOver too.like without the text appearing when rollovered, the user will have no idea what they’re clicking on. (-:

is it real hard to modify the script? if u can add it in to the grey box, thatll be sweet. also, where would i add the getURL code after the user clicks on the button?

i know im being a pain, but i kinda need it to work like that for a class project. i promise this will be the last time ill ask u about “rollover, click and stay”.

thanks!

Ok. I just had to modify a few things in the way the script worked. And I added another trigger.

The script is fully commented. If you have any questions, just ask :slight_smile:

And the getURL will go under the onPress.

i was making a display with buttons on the bottom when i realized something. after clicking on a button, the text stays put. but when i rollover another button, the 2nd text overlaps the other one making it unreadable. is there a way to hide the text thats previously clicked on when another button is mouseovered?
i know its my fault, i just remembered i wanted all the text to appear on a box…mustve been drinking too much. heres the fla.
thanks!

Well that would be the purpose of the pressed trigger :wink:

If one is pressed, you can tell use that variable assigned for button 2 as well.

Something like this in the on(rollOver) (untested)…

if (_root.onePressedTrigger) {
		_root.oneText._visible = false;
	}

And something like this in the on(rollOut)…

if (_root.onePressedTrigger) {
		_root.oneText._visible = true;
	}

You can do the same on button 1 just change it to make the twoText visible and stuff and stuff… yeah.

Hopefully that makes sense… :trout: << to me

thanks alot for your help! it works! :beam:

Wahoo =)