# Second if statement doesn't evaluate

**URL:** <https://forum.kirupa.com/t/second-if-statement-doesnt-evaluate/5254>\
**Category:** Uncategorized\
**Created:** [September 5, 2002, 7:37pm UTC](https://forum.kirupa.com/t/second-if-statement-doesnt-evaluate/5254 "2002-09-05T19:37:28Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbest](https://avatars.discourse-cdn.com/v4/letter/j/f475e1/32.png) [@jbest](https://forum.kirupa.com/u/jbest)\
**Post date:** [September 5, 2002, 7:37pm UTC](https://forum.kirupa.com/t/second-if-statement-doesnt-evaluate/5254/1 "2002-09-05T19:37:28Z")

</div>

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 ;(

---

<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:** [September 5, 2002, 7:45pm UTC](https://forum.kirupa.com/t/second-if-statement-doesnt-evaluate/5254/2 "2002-09-05T19:45:54Z")

</div>

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.

---

<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:** [September 5, 2002, 9:24pm UTC](https://forum.kirupa.com/t/second-if-statement-doesnt-evaluate/5254/3 "2002-09-05T21:24:33Z")

</div>

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 🙂

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.

---

<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:** [September 5, 2002, 9:39pm UTC](https://forum.kirupa.com/t/second-if-statement-doesnt-evaluate/5254/4 "2002-09-05T21:39:51Z")

</div>

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

---

<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:** [September 5, 2002, 11:09pm UTC](https://forum.kirupa.com/t/second-if-statement-doesnt-evaluate/5254/5 "2002-09-05T23:09:53Z")

</div>

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.

---

<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:** [September 6, 2002, 2:36pm UTC](https://forum.kirupa.com/t/second-if-statement-doesnt-evaluate/5254/6 "2002-09-06T14:36:27Z")

</div>

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.

---

<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:** [September 6, 2002, 2:38pm UTC](https://forum.kirupa.com/t/second-if-statement-doesnt-evaluate/5254/7 "2002-09-06T14:38:39Z")

</div>

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

---

<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:** [September 9, 2002, 6:49am UTC](https://forum.kirupa.com/t/second-if-statement-doesnt-evaluate/5254/8 "2002-09-09T06:49:47Z")

</div>

To differentiate variable setting and evaluating 🙂

pom :asian:
