View Full Version : Actionscript with alpha
Titoqan
May 29th, 2002, 12:52 PM
Thanks for helping me with my other questions, here is another one.
What I want to do is fade one image out while fading another image in. The script that I am using fades one image to alpha 0 then fades the next one in to alpha 100.
The script that I am using is this.
On first frame of main timeline
back._visible=false;
function goPage(whichWay){
slides.alphaChange=-5;
slides.destinationFrame=slides._currentFrame+which way;
back._visible=(slides.destinationFrame<>1);
forward._visible=(slides.destinationFrame<>slides._totalFrames);
}
On MC named "slides" has a single image on each frame.
onClipEvent (load) {
        stop ();
}
onClipEvent (enterFrame) {
_alpha+=alphaChange;
if (_alpha<1) {
gotoAndStop (destinationFrame);
alphaChange=5;
}
if (_alpha>100) {
alphaChange=0;
}
}
on Button to advanced to next image
on (release) {
        _root.goPage(buttonDirection);
}
This script works fine but I want to modify it.
Thanks,
Matt
ilyaslamasse
May 29th, 2002, 01:23 PM
Oh my... Your code is hard to understand Matt. Anyway, why do you want to change your code if it works ?
pom 0]
msjensen
May 29th, 2002, 01:35 PM
Thanks Pom for checking this post. msjensen and Titoqan is one and the same, me.
The reason I want to change it is because it fades out one image completly then fade the next image in.
I forgot to mention that I have two buttons botth in thier own MC one for forward named "forward" and one for back named "back". both buttons have the same code.
What I want to have happen is as one image fades out the second image fades in. This will allow the viewer to see the changes and differences of the two images. The images are photo-simulations which are a before and after.
I got the code from a PDF that I downloaded along time ago and I can't remember the author, sorry.
Would it be easier to look at the .fla?
Matt
ilyaslamasse
May 29th, 2002, 01:55 PM
I guess. That way, everybody could have a look.
pom 0]
msjensen
May 29th, 2002, 04:08 PM
Your right Pom so here is the .fla. this is what I downloaded with a .pdf, I am posting this fla because it is smaller than the one I have made.
www.msyverjensen.0catch.c...shop_5.fla (http://www.msyverjensen.0catch.com/workshop_5.fla)
here is what it does.
www.msyverjensen.0catch.c...hop_5.html (http://www.msyverjensen.0catch.com/workshop_5.html)
Thanks
Matt
msjensen
June 5th, 2002, 11:20 AM
Just bumping this to see if I can get another response.
Thanks,
Matt
geekmanX
June 5th, 2002, 12:50 PM
Wouldnt it be easier to use two layers, and fade them in manually?
ilyaslamasse
June 5th, 2002, 01:02 PM
That's also a good idea, though it would be difficult if you have a lot of pictures...
pom 0]
ilyaslamasse
June 5th, 2002, 01:41 PM
Ok, here's what I came up with :
I have 2 buttons on my scene whose instance names are forward and backward.
I have 3 movies in my library whose linkage names are movie1, movie2 and movie3.
Then in the first and only frame of my animation, I have this code :
fadeIn = function () {
if (this._alpha <= 100) {
this._alpha += 5 ;
}
else this.onEnterFrame = null ;
}
fadeOut = function () {
if (this._alpha >= 0) this._alpha -= 5 ;
else this.removeMovieClip () ;
}
_root.onLoad = function () {
pos = 1 ;
this.attachMovie (myMovies[pos-1],"t"+pos,pos) ;
var mc = this["t"+pos] ;
mc._x = 200 ;
mc._y = 200 ;
mc._alpha = 0 ;
mc.onEnterFrame = fadeIn ;
}
forward.onPress = function () {
if (pos < myMovies.length) {
_root["t"+pos].onEnterFrame = fadeOut ;
pos ++ ;
_root.attachMovie (myMovies[pos-1],"t"+pos,pos) ;
var mc = _root["t"+pos] ;
mc._x = 200 ;
mc._y = 200 ;
mc._alpha = 0 ;
mc.onEnterFrame = fadeIn ;
}
}
backward.onPress = function () {
if (pos > 1 ) {
_root["t"+pos].onEnterFrame = fadeOut ;
pos -- ;
_root.attachMovie (myMovies[pos-1],"t"+pos,pos) ;
var mc = _root["t"+pos] ;
mc._x = 200 ;
mc._y = 200 ;
mc._alpha = 0 ;
mc.onEnterFrame = fadeIn ;
}
}
// Array of movies
myMovies = new Array ("movie1","movie2","movie3" ) ;Does that make sense to you ? Actually, the code could be shorter, but I didn't have time (only one 'fade' function, and a function to attach movies...).
pom 0]
ilyaslamasse
June 5th, 2002, 03:02 PM
Version 2.0
fadeIn = function () {
        if (this._alpha <= 100) {
                this._alpha += 5 ;
                }
        else this.onEnterFrame = null ;
}
fadeOut = function () {
        if (this._alpha >= 0) this._alpha -= 5 ;
        else this.removeMovieClip () ;
}
attach = function (number) {
        _root.attachMovie (myMovies[number-1],"t"+number,number) ;
        var mc = _root["t"+pos] ;
        mc._x = 200 ;
        mc._y = 200 ;
        mc._alpha = 0 ;
        mc.onEnterFrame = fadeIn ;
}
_root.onLoad = function () {
        pos = 1 ;
        _root.attach(pos) ;
}
forward.onPress = function () {
        if (pos < myMovies.length) {
                _root["t"+pos].onEnterFrame = fadeOut ;
                pos ++ ;
                _root.attach(pos) ;
        }
}
backward.onPress = function () {
        if (pos > 1 ) {
                _root["t"+pos].onEnterFrame = fadeOut ;
                pos -- ;
                _root.attach(pos) ;
        }
}
// Array of movies
myMovies = new Array ("movie1","movie2","movie3" ) ;Good thing is : it works with any number of movies, and very very easily. :D
pom 0]
ilyaslamasse
June 5th, 2002, 06:09 PM
Version 3 complete !! You can grab it there membres.lycos.fr/museebra...rkshop.zip (http://membres.lycos.fr/museebranly/flash/Workshop.zip)
msjensen
June 9th, 2002, 04:15 PM
Pom, the flash file you sent me I could not open it says it does not recognize the file format. Could it be a flash mx file? I am still using flash 5.
Thanks,
Matt
ilyaslamasse
June 9th, 2002, 04:50 PM
Yep, that's Flash MX, sorry... Actually, it's much easier in Flash MX, but I'll try and make a F5 version. Sure you don't wanna buy MX ?? :D
pom 0]
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.