View Full Version : best way in flash mx
jimw00d
January 8th, 2003, 03:23 AM
I've seen lots of threads on achieving an alpha fade effect using actionscript. I want to be able to adjust the alpha of an Mc using a button instance.
I've experimented with a few techniques using loops and hitTest but at the moment on mouseOver for example the alpha only increases the once until the mouse is taken away and placed over the button again. Obviously I need to achieve a continual evaluation of the mouse position or hitTest in order to achieve a continuous fade effect.
Also how would I ensure that a Mc faded out when the mouse comes away from the button.
I guess what I am asking for is a way of creating a fade in and out on a Mc with a remote button.
Any ideas? I'm sure there are
Regards:rambo:
lostinbeta
January 8th, 2003, 03:29 AM
Well an on (rollOver) is only per time you rollOver. What you would need for gradual is to have an enterFrame thing going on.
To do this your button will first have to be a movie clip.
Then on that movie clip you would apply these actions...
on (rollOver) {
this.onEnterFrame = function() {
this._alpha += 5;
if (this._alpha>=100) {
this._alpha = 100;
delete this.onEnterFrame;
}
};
}
on (rollOut) {
this.onEnterFrame = function() {
this._alpha -= 5;
if (this._alpha<=0) {
this._alpha = 0;
delete this.onEnterFrame;
}
};
}
What this does is.. onRollOver it starts an onEnterFrame handler, which will keep updating the code when the movieclip enters the frame (repeatedly that is). So it will increase by 5 until it gets to 100, when it gets there it will stay there and then delete the onEnterFrame so as to preserve CPU resources.
Next is the onRollOut, same method as the onRollOver, but subtracts 5 from the _alpha. And waits until it gets to 0 then deletes the onEnterFrame.
lostinbeta
January 8th, 2003, 03:33 AM
Or for easier updating you can use variables to set the speed, high alpha number and low alpha number, then the default alpha on startup, like this...
onClipEvent (load) {
highMax = 100;
lowMax = 30;
speed = 5;
this._alpha = lowMax;
}
on (rollOver) {
this.onEnterFrame = function() {
this._alpha += speed;
if (this._alpha>=highMax) {
this._alpha = highMax;
delete this.onEnterFrame;
}
};
}
on (rollOut) {
this.onEnterFrame = function() {
this._alpha -= speed;
if (this._alpha<=lowMax) {
this._alpha = lowMax;
delete this.onEnterFrame;
}
};
}
jimw00d
January 8th, 2003, 03:42 AM
How would a remote button, or Mc posing as a button, work in this case to create the effect you describe on a different Mc on the stage?
So I would have two Mcs on the stage, (1)-Mc posing as a button to create the fade in and fade out on (2)-the Mc to be faded in and out.
lostinbeta
January 8th, 2003, 03:43 AM
change "this" which targets the clip the actions are on to "_root.yourClip" which targets another movieclip on the _root timeline with the instance name "yourClip" (no quotes).
blah-de-blah
January 8th, 2003, 03:47 AM
i'm guessing here, but how bout changing the 'this' 's into the other mc instance name..!? maybe i'llt ry it and tell you if it works..
blah-de-blah
January 8th, 2003, 03:48 AM
nvm i was too late....:(
lostinbeta
January 8th, 2003, 03:50 AM
Alrighty, I am off to bed, 3:50am here.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.