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);
}
Try this:
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:
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.
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]
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]
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];
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]
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.
Thank you so much glosrfc, it worked like a charm, really appreciate the help