# Simple, maybe not right?

**URL:** https://forum.kirupa.com/t/simple-maybe-not-right/262048
**Category:** flash
**Created:** [June 2, 2008, 10:48pm UTC](https://forum.kirupa.com/t/simple-maybe-not-right/262048 "2008-06-02T22:48:52Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Grimmit](https://avatars.discourse-cdn.com/v4/letter/g/3ab097/32.png) [@Grimmit](https://forum.kirupa.com/u/Grimmit)
#### Post date: [June 2, 2008, 10:48pm UTC](https://forum.kirupa.com/t/simple-maybe-not-right/262048/1 "2008-06-02T22:48:52Z")

</div>

I am not very code oriented, but I found this code that I altered for my needs, and it works, as you move your cursor towards the bottom of the screen the movie clip fades in. However, in addition I need one that does the inverse where another mc fades in as you approach the top. Does anyone know how I would acomplish this task? Thank you

> 

mouseInterval = setInterval(changeAlpha,10);

function changeAlpha() {  
faded\_mc.\_alpha = Math.round(\_root.\_ymouse/500\*150);  
}

---

<div class="post-metadata">

### Author: ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)
#### Post date: [June 2, 2008, 11:35pm UTC](https://forum.kirupa.com/t/simple-maybe-not-right/262048/2 "2008-06-02T23:35:26Z")

</div>

Try this:

```auto
mouseInterval = setInterval(changeAlphaUp, 10);
function changeAlphaUp() {
	faded_mc._alpha = Math.round((Stage.height - _root._ymouse) / Stage.height * 100);
}

```

You could also use the following instead of your original function:

```auto
function changeAlphaDown() {
	faded_mc._alpha = Math.round(_root._ymouse / Stage.height * 100);
	trace (_root._ymouse / Stage.height * 100);
}

```

The only difference is that it will still work regardless of the size of your stage. Hope that helps.

---

<div class="post-metadata">

### Author: ![Grimmit](https://avatars.discourse-cdn.com/v4/letter/g/3ab097/32.png) [@Grimmit](https://forum.kirupa.com/u/Grimmit)
#### Post date: [June 2, 2008, 11:44pm UTC](https://forum.kirupa.com/t/simple-maybe-not-right/262048/3 "2008-06-02T23:44:30Z")

</div>

The first code doesn’t seem to have any affect, or do anything, and the second one comes back with syntax errors, was I supposed to substitue anything in anywhere? Thanks for the reply[quote=glosrfc;2335184]Try this:  
ActionScript Code:  
[LEFT]mouseInterval = [COLOR=#0000FF]setInterval[/COLOR][COLOR=#000000]([/COLOR]changeAlphaUp, [COLOR=#000080]10[/COLOR][COLOR=#000000])[/COLOR];  
[COLOR=#000000] **function** [/COLOR] changeAlphaUpCOLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
&nbsp;&nbsp;&nbsp;&nbsp;faded\_mc.[COLOR=#0000FF]\_alpha[/COLOR] = [COLOR=#0000FF]Math[/COLOR].[COLOR=#0000FF]round[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000]([/COLOR][COLOR=#0000FF]Stage[/COLOR].[COLOR=#0000FF]height[/COLOR] - [COLOR=#0000FF]\_root[/COLOR].[COLOR=#0000FF]\_ymouse[/COLOR][COLOR=#000000])[/COLOR] / [COLOR=#0000FF]Stage[/COLOR].[COLOR=#0000FF]height[/COLOR] \* [COLOR=#000080]100[/COLOR][COLOR=#000000])[/COLOR];  
[COLOR=#000000]}[/COLOR]  
[/LEFT]

You could also use the following instead of your original function:  
ActionScript Code:  
[LEFT][COLOR=#000000] **function** [/COLOR] changeAlphaDownCOLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
&nbsp;&nbsp;&nbsp;&nbsp;faded\_mc.[COLOR=#0000FF]\_alpha[/COLOR] = [COLOR=#0000FF]Math[/COLOR].[COLOR=#0000FF]round[/COLOR][COLOR=#000000]([/COLOR][COLOR=#0000FF]\_root[/COLOR].[COLOR=#0000FF]\_ymouse[/COLOR] / [COLOR=#0000FF]Stage[/COLOR].[COLOR=#0000FF]height[/COLOR] \* [COLOR=#000080]100[/COLOR][COLOR=#000000])[/COLOR];  
&nbsp;&nbsp;&nbsp;&nbsp;trace [COLOR=#000000]([/COLOR][COLOR=#0000FF]\_root[/COLOR].[COLOR=#0000FF]\_ymouse[/COLOR] / [COLOR=#0000FF]Stage[/COLOR].[COLOR=#0000FF]height[/COLOR] \* [COLOR=#000080]100[/COLOR][COLOR=#000000])[/COLOR];  
[COLOR=#000000]}[/COLOR]  
[/LEFT]

The only difference is that it will still work regardless of the size of your stage. Hope that helps.[/quote]

---

<div class="post-metadata">

### Author: ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)
#### Post date: [June 3, 2008, 12:00am UTC](https://forum.kirupa.com/t/simple-maybe-not-right/262048/4 "2008-06-03T00:00:45Z")

</div>

Not sure where the non-breaking spaces came from…however both functions do work. The only change is to the formula that calculates the alpha value of the movieclip. It should be easy enough to figure out what it’s doing in each case:  
(stage height - mouse position) / stage height \* 100 causes the alpha value to increase as you move the mouse upwards  
mouse position / stage height \* 100 causes the alpha value to increase as you move the mouse downwards

That’s why I left the trace statement in the one example, so that you can see how it works.

---

<div class="post-metadata">

### Author: ![Grimmit](https://avatars.discourse-cdn.com/v4/letter/g/3ab097/32.png) [@Grimmit](https://forum.kirupa.com/u/Grimmit)
#### Post date: [June 3, 2008, 12:19am UTC](https://forum.kirupa.com/t/simple-maybe-not-right/262048/5 "2008-06-03T00:19:50Z")

</div>

Thank you so much glosrfc, it worked like a charm, really appreciate the help
