HOME       >>       Programming

Mouse Over Alpha Fade Flash CS3

Two Gun Charley

Hey team,New to the forums and new to Flash. I'm trying to work out what script I need to use in order to make a movie clip (a grey square if it matters) change alpha qualities when you roll the mouse over it. I also want it to stop and fade back to it's original form when you move the mouse off it. I've got it working just using a button symbol but when I take the mouse of it just jumps straight back to the original form (ie. no 'fade out') and it also repeats itself. I've googled it, and done a search on the forums. I'm sure it's a simple solutions. Thanks in advance for your help!


Some on that effect here

Basically you just use setInterval to call a function every now and then.

In more depth ->
Have a function which is called by setInterval:
->Lowers the alpha
->Clear the interval is the alpha is low enough
Have another function that increases the alpha instead
When you roll over, call setInterval for decreasing alpha, clear interval for increasing alpha
When you roll out, clear the interval for decreasing alpha and set interval for increasing alpha

Code (I have the object named 'ob', ideally you would use this._alpha except I couldn't get it working and I've got to go now..)

onClipEvent (load) { function DecreaseAlpha () { _root.ob._alpha -= 2; if (_root.ob._alpha <= 50) { clearInterval (DecreaseAlphaInterval); } } function IncreaseAlpha () { _root.ob._alpha += 2; if (_root.ob._alpha >= 100) { clearInterval (IncreaseAlphaInterval); } }}on (rollOver) { DecreaseAlphaInterval = setInterval (DecreaseAlpha, 40); clearInterval (IncreaseAlphaInterval);}on (rollOut) { IncreaseAlphaInterval = setInterval (IncreaseAlpha, 40); clearInterval (DecreaseAlphaInterval);}

Two Gun Charley

Thanks for that man, really appreciate it. Works sweet as!

Got an even more new jack question now. I'm trying to get the movie clips that I added that script to, to now act as buttons and link to the first frame on a few other scenes.

So I tryed to add this to the top of the actions pannel (above that alpha fade script);

on (release) {gotoAndPlay("scene1",1);}

But no dice. Any ideas?

Thanks again man. Struggling threw this a wee bit, as you can tell.


I think that's a problem of scope (it's a killer when you're starting flash if you don't have programming experience). Changing it to _root.gotoAndPlay should suffice. If you leave the _root out, I think it would try to make the button go to frame 'scene1'.

Two Gun Charley

Hey man, cheers for that. Didn't work though. Could it be an issue with the rollover script over riding the release script? I trying adding the script with the _root in it to a new button I made up and it worked sweet as.


I like to put all my actions on frames instead of putting them on buttons or clips. It makes the .fla look clean and the actions easier to follow.
This is the code I used on the second frame:

stop();function DecreaseAlpha (){ _root.button._alpha -= 2; if (_root.button._alpha <= 50){ clearInterval (DecreaseAlphaInterval); }};function IncreaseAlpha (){ _root.button._alpha += 2; if (_root.button._alpha >= 100){ clearInterval (IncreaseAlphaInterval); }};_root.button.onRollOver = function(){ DecreaseAlphaInterval = setInterval (DecreaseAlpha, 40); clearInterval (IncreaseAlphaInterval);}_root.button.onRollOut = function(){ IncreaseAlphaInterval = setInterval (IncreaseAlpha, 40); clearInterval (DecreaseAlphaInterval);}_root.button.onRelease = function(){ gotoAndStop(1);}

It looks a lot like Nabb's code because I copied his code and modified it
Here's my *fla if you need it: http://110mb.com/404.php (Right Click, Save As)
It may help to look at a live, working example rather than at a code.

Two Gun Charley

Yeah cheers man, put the navigation actions on a frame in a function and it works sweet as.

Got the site live. You can check it out here; http://www.bairstow.co.nz/david/

It's working sweet as, just some crazy stuff happens with the alpha fades when you return to the opening scene. If you click the second bar, then the 'take me back' button, the second bar then fades out to background colour.

Anyone know what all that's about? You can download the .fla file here http://forums.xisto.com/no_longer_exists/

Thanks in advance guys.


Replying to Two Gun CharleyHello there, I,m from the Netherlands. I want the fade in/out action on mouse over/off on a silhouet of a person.So when you open the page you see the grey silhouet, but when you go over it with your mouse it will SLOWLY appear in full colour.Can you tell me (please step by step) how to make such an action?Lots of thanks...Greetz Ronald (Netherlands) -reply by ronald


It seems to work fine with Mozilla Firefox 3, but when I use Internet Explorer 7 every bar blends into the background when I click 'take me back'.I'll take a look at the .fla , but I can't promise I'll be able to help.


thanks einreaper! but how do I use this if I have more buttons on my scene?cheers,johan

-reply by johan



multiple actions on frameMouse Over Alpha Fade

I would also like to know how to use Einreaper's method for multiple buttons. When I try to duplicate the code and change the button names it doesn't work. Please help. I have a feeling it has to do with how the code is closed within.

I have several buttons (button1, button2, button3, etc) and would like to apply the alpha rollover/rollout to all the buttons and code it all on a single frame.

 Thank you.

-reply by theloomis


Xisto.com offers Free Web Hosting to its Members for their participation in this Community. We moderate all content posted here but we cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our terms of use, cookie and privacy policy. Copyright 2001-2019 by Xisto Corporation. All Rights Reserved.