Second if statement doesn't evaluate

I am trying to make a mask gradually get darker when the user hovers over a certain area. I created an object called mask, and 2 keyframes with actionscript. Here is the first:

var hover;
if ((_xmouse>10 and _xmouse<470 and _ymouse>60 and _ymouse<110) or (_xmouse>10 and _xmouse<100 and _ymouse>10 and _ymouse<60) or (_xmouse>370 and _xmouse<470 and _ymouse>10 and _ymouse<60)) {
hover = true;
} else {
hover = false;
}
if (hover=true and mask._alpha<60) {
mask._alpha++;
} else if (hover=false and mask._alpha>0) {
mask._alpha–;
}
title.text = hover;

here is the second:
gotoAndPlay(1);

Pretty simple, eh? Hovering over that space sets hover to true, which will increase the alpha on the mask slowly to 60. Otherwise, it will decrease the alpha until it is 0. I’ve also set up a dynamic text box (title) to show me the state of hover at all times.
However, this is what happens - when it first loads, it says hover = true, and the mask gradually gets darker, even though my mouse isn’t even hovering over any part of the animation. When the alpha on the maks reaches 60%, it stops getting darker and hover changes to false. Even if I hover over the specified space, it won’t change hover to true, and it won’t decrement the mask alpha.

Any ideas? I’m stumped ;(

First have you tried

var hover;
if ((_xmouse>10 and _xmouse<470 and _ymouse>60 and _ymouse<110) or (_xmouse>10 and _xmouse<100 and _ymouse>10 and _ymouse<60) or (_xmouse>370 and _xmouse<470 and _ymouse>10 and _ymouse<60)) {
hover = true;
} else {
hover = false;
}
[COLOR=blue]if ((hover == true) && (mask._alpha<60))[/COLOR] {
mask._alpha++;
} else [COLOR=blue]if ((hover == false) && (mask._alpha>0))[/COLOR] {
mask._alpha–;
}
title.text = hover;

Also I’m not sure exactly what you’re after, but instead of using the if_xmouse and _ymouse to see if it’s over certain coordinates (can be pretty confusing) why don’t you use on the area (make it into a movie clip):

[COLOR=blue]onClipEvent (mouseMove) {
if ((this.hitTest(_root._xmouse, _root._ymouse, true)))
{
Put code here
}
}[/COLOR]

then when the mouse is over any part of the movie clip the hitTest will register true and the code in the if statement will be run.

thanks, flex - that was just what I needed.

Looks like my = were just single =, which I guess set the value instead of evaluating it. oops :slight_smile:

I’ve been messing with your other idea (since I am trying to make the mask fade into view when I hover over a button / movie clip)and I got it to work, but it only increments when you actually move the mouse, so holding the mouse over the button or movie clip only increments one, instead of incrementing slowly until it reaches 60.

Do you know of a better way to do this? I could use “while”, but that just increments to 60 almost immediately, instead of doing it once every fps.

I see what you mean. I’ll have a look.

I think this should work.

Instead of

[COLOR=blue]onClipEvent (mouseMove) {
if ((this.hitTest(_root._xmouse, _root._ymouse, true)))
{
//code
}
}[/COLOR]

Use

[COLOR=blue]onClipEvent (enterFrame) {
if ((this.hitTest(_root._xmouse, _root._ymouse, true)))
{
//code
}
}[/COLOR]

This way every time the clip enters a frame if the x and y of the mouse is over the movie clip, the code should be run.

that works, but I can’t figure out how to make it stop at 60% alpha that way.

I actually found another way of doing exactly what I want through variables, and it seems to work better.

Thank you very much for your help, flex! It’s amazing what you can learn from one post on this forum.

yeah its weird how it needs the two == in the if’s does anyone know why this is?

To differentiate variable setting and evaluating :slight_smile:

pom :asian: