Groups | Blog | Home
all groups > flash actionscript > july 2006 >

flash actionscript : Fade effect: how to do with "onEnterFrame"?


Nickname339966
7/22/2006 10:59:41 PM
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.
jonnybennett
7/23/2006 3:25:34 PM
I've not teste this, but could you not use set INterval so that it executes
until the alpha=100, and then clearthe interval...

on (rollOver) {
myInterval=setInterval(_root.showCity(),1);
}
on (rollOut) {
myInterval2=setInterval(_root.hideCity(),1);
}


then in your functions...

function showCity(){
city._alpha += _root.speedIn;
if (city._alpha > 100){
city._alpha = 100;
clearInterval(myInterval);
}}

function hideCity(){
city._alpha -= _root.speedOut;
if (city._alpha < 0){
city._alpha = 0;
clearInterval(myInterval2);
}}

I'm not sure if this works, but hopfully it should.
Nicholas Wood
9/1/2006 12:00:00 AM
AddThis Social Bookmark Button