all groups > flash actionscript > july 2006 >
You're in the

flash actionscript

group:

Fade effect: how to do with "onEnterFrame"?


Fade effect: how to do with "onEnterFrame"? Nickname339966
7/22/2006 10:59:26 PM
flash actionscript:
Hi,
I have a map with each city represented as a dot (MC). When you mouse over the
dot, another MC with more city details/text quickly fades in, and fades out
when you roll out. But I can't get the full fade effect working. Need your
advice...

In the dot MC, I put:

on (rollOver) {
_root.showCity();
}
on (rollOut) {
_root.hideCity();
}


In the root, showCity() and hideCity() are functions to fade in and out the
city details MC (city_sanfrancisco). I figured they should be at the root level
so they can be used by other city dots (city_sandiego, city_boston, etc.) as
well:

//this lets me change the speed for fading in and another speed for fading out
var speedIn;
speedIn = 20;
var speedOut;
speedOut = 20;

//hard-coded city for now; set city to invisible when movie starts
var city = city_sanfrancisco;
city._alpha = 0;

//this shows the city details by fading in
function showCity(){
city._alpha += _root.speedIn;
if (city._alpha > 100){
city._alpha = 100;
}
}
function hideCity(){
city._alpha -= _root.speedOut;
if (city._alpha < 0){
city._alpha = 0;
}
}

What this doesn't do is the full fade effect, because the function only
executes once, so city._alpha doesn't reach 100 when it fades in. I've seen in
other fade effect scripts, that they use the enterFrame event, but I don't now
how to use it here... or what is the right syntax to make the city details MC
fade in to 100% on rollOver, and fade out to 0 on rollOut... and still be able
to apply a speed setting.

Any help would be appreciated.
Re: Fade effect: how to do with "onEnterFrame"? Nickname339966
7/23/2006 12:00:00 AM
Hi Sinead,
Thanks. I tried it but it didn't work. The fade in seems to execute the same as before... only fading in 20%.

Re: Fade effect: how to do with "onEnterFrame"? micahkoga
7/23/2006 12:00:00 AM
You might want to try the tween class for simplicity:



import mx.transitions.Tween;

function showCity(){
new Tween(city, "_alpha", Elastic.easeOut, city._alpha, 100, duration, true);
}
function hideCity(){
new Tween(city, "_alpha", Elastic.easeOut, city._alpha, 0, duration, true);
}
Re: Fade effect: how to do with "onEnterFrame"? SineadOT
7/23/2006 12:24:12 AM
you could try something like this:

on(rollOver){
onEnterFrame = showCity;
}
then modify your showCity function slightly:
function showCity(){
city._alpha += _root.speedIn;
if (city._alpha > 100){
city._alpha = 100;
delete onEnterFrame;
}
}
.. with similar adjustments to you on rollOut code.

Hope this helps,
Sinead.
AddThis Social Bookmark Button