I am trying to change the alpha of a movie clip using if statement.
I have done this but i want to change the alpha using a fade in way.
e.g. From 100% fade to 0% using a motion tween.
I am wondering if you can do such an effect using only actionsript!
In the example i have created some movie clips turning off & on their alpha, but i didn't manage to do it using any fade effect.
I have just seen the fla.
Its exactly what i wanted. I am glad.
Although, i want to ask you for a few more things about it!
what changes i have to do if i want not to use 5 frames for the fade out?
e.g. when you press the button fade in using 5 frames, when press again fade out instantly.
And something more....When you press and see the fade in, play a sound as well, when press again not hear the sound.
I dont know how complicate things go, if its a problem, forget it.
for (var i = 0; i < 5; ++i) {
this["red" + i].dest = 100;
this["red" + i].ease = 1;
this["btn" + i].id = i;
this["btn" + i].onPress = function() {
// store a reference to the clip we'll be targeting in a variable to save us having to type out the whole target path several times
var mc = this._parent["red" + this.id];
if (mc.dest == 100) {
mc.dest = 0;
mc.ease = 1;
} else {
mc.dest = 100;
mc.ease = 5;
}
mc.onEnterFrame = fade;
};
}
if you wanted a sound to play as the clip faded in (this assumes each clip plays the same sound) you could import your sound into the movie, using
file > import
then find the sound file in the library, right click on its name and choose linkage from the options. in the linkage dialog box, select export for actionscript and fill in the identifier field (in this example I used the identifier bgm) now in your movie your frame actions could become,
code:
var mySound = new Sound(this); // create a new sound object
mySound.attachSound("bgm"); // associate it with the your sound file