Actionscript with alpha

Thanks for helping me with my other questions, here is another one.\r\rWhat 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.\r\rThe script that I am using is this.\r\rOn first frame of main timeline\r\rback._visible=false;\rfunction goPage(whichWay){\r slides.alphaChange=-5;\r slides.destinationFrame=slides._currentFrame+whichway;\r back._visible=(slides.destinationFrame<>1);\r forward._visible=(slides.destinationFrame<>slides._totalFrames);\r}\r\r\rOn MC named “slides” has a single image on each frame.\ronClipEvent (load) {\r&nbsp &nbsp &nbsp &nbsp stop ();\r}\ronClipEvent (enterFrame) {\r _alpha+=alphaChange;\r if (_alpha<1) {\r gotoAndStop (destinationFrame);\r alphaChange=5;\r }\r if (_alpha>100) {\r alphaChange=0;\r }\r}\r\ron Button to advanced to next image\r\ron (release) {\r&nbsp &nbsp &nbsp &nbsp _root.goPage(buttonDirection);\r}\r\rThis script works fine but I want to modify it.\r\rThanks,\rMatt

Oh my… Your code is hard to understand Matt. Anyway, why do you want to change your code if it works ?\r\rpom 0]

Thanks Pom for checking this post. msjensen and Titoqan is one and the same, me.\r\rThe reason I want to change it is because it fades out one image completly then fade the next image in.\r\rI 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.\r\rWhat 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.\r\rI got the code from a PDF that I downloaded along time ago and I can’t remember the author, sorry.\r\rWould it be easier to look at the .fla?\r\rMatt

I guess. That way, everybody could have a look.\r\rpom 0]

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.\r\rwww.msyverjensen.0catch.c…shop_5.fla\r\r\rhere is what it does.\r[url=“http://www.msyverjensen.0catch.com/workshop_5.html”]www.msyverjensen.0catch.c…hop_5.html\r\rThanks\rMatt

Just bumping this to see if I can get another response.\r\rThanks,\rMatt

Wouldnt it be easier to use two layers, and fade them in manually?

That’s also a good idea, though it would be difficult if you have a lot of pictures…\r\rpom 0]

Ok, here’s what I came up with :\rI have 2 buttons on my scene whose instance names are forward and backward.\rI have 3 movies in my library whose linkage names are movie1, movie2 and movie3.\rThen in the first and only frame of my animation, I have this code :

  fadeIn = function () {\r\r        if (this._alpha <= 100) {\r\r                this._alpha += 5 ;\r\r                }\r\r        else this.onEnterFrame = null ;\r\r}\r\r\r\rfadeOut = function () {\r\r        if (this._alpha >= 0) this._alpha -= 5 ;\r\r        else this.removeMovieClip () ;\r\r}\r\r_root.onLoad = function () {\r\r        pos = 1 ;\r\r        this.attachMovie (myMovies[pos-1],"t"+pos,pos) ;\r\r        var mc = this["t"+pos] ;\r\r        mc._x = 200 ;\r\r        mc._y = 200 ;\r\r        mc._alpha = 0 ;\r\r        mc.onEnterFrame = fadeIn ;\r\r}\r\r\r\rforward.onPress = function () {\r\r        if (pos < myMovies.length) {\r\r                _root["t"+pos].onEnterFrame = fadeOut ;\r\r                pos ++ ;\r\r                _root.attachMovie (myMovies[pos-1],"t"+pos,pos) ;\r\r                var mc = _root["t"+pos] ;\r\r                mc._x = 200 ;\r\r                mc._y = 200 ;\r\r                mc._alpha = 0 ;\r\r                mc.onEnterFrame = fadeIn ;\r\r        }\r\r}\r\r\r\rbackward.onPress = function () {\r\r        if (pos > 1 ) {\r\r                _root["t"+pos].onEnterFrame = fadeOut ;\r\r                pos -- ;\r\r                _root.attachMovie (myMovies[pos-1],"t"+pos,pos) ;\r\r                var mc = _root["t"+pos] ;\r\r                mc._x = 200 ;\r\r                mc._y = 200 ;\r\r                mc._alpha = 0 ;\r\r                mc.onEnterFrame = fadeIn ;\r\r        }\r\r}\r\r\r\r// Array of movies\r\rmyMovies = 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…).\r\rpom 0]

Version 2.0

 fadeIn = function () {\r\r&nbsp &nbsp &nbsp &nbsp if (this._alpha <= 100) {\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp this._alpha += 5 ;\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp }\r\r&nbsp &nbsp &nbsp &nbsp else this.onEnterFrame = null ;\r\r}\r\r\r\rfadeOut = function () {\r\r&nbsp &nbsp &nbsp &nbsp if (this._alpha >= 0) this._alpha -= 5 ;\r\r&nbsp &nbsp &nbsp &nbsp else this.removeMovieClip () ;\r\r}\r\r\r\rattach = function (number) {\r\r&nbsp &nbsp &nbsp &nbsp _root.attachMovie (myMovies[number-1],"t"+number,number) ;\r\r&nbsp &nbsp &nbsp &nbsp var mc = _root["t"+pos] ;\r\r&nbsp &nbsp &nbsp &nbsp mc._x = 200 ;\r\r&nbsp &nbsp &nbsp &nbsp mc._y = 200 ;\r\r&nbsp &nbsp &nbsp &nbsp mc._alpha = 0 ;\r\r&nbsp &nbsp &nbsp &nbsp mc.onEnterFrame = fadeIn ;\r\r}\r\r\r\r_root.onLoad = function () {\r\r&nbsp &nbsp &nbsp &nbsp pos = 1 ;\r\r&nbsp &nbsp &nbsp &nbsp _root.attach(pos) ;\r\r}\r\r\r\rforward.onPress = function () {\r\r&nbsp &nbsp &nbsp &nbsp if (pos < myMovies.length) {\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp _root["t"+pos].onEnterFrame = fadeOut ;\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp pos ++ ;\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp _root.attach(pos) ;\r\r&nbsp &nbsp &nbsp &nbsp }\r\r}\r\r\r\rbackward.onPress = function () {\r\r&nbsp &nbsp &nbsp &nbsp if (pos > 1 ) {\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp _root["t"+pos].onEnterFrame = fadeOut ;\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp pos -- ;\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp _root.attach(pos) ;\r\r&nbsp &nbsp &nbsp &nbsp }\r\r}\r\r\r\r// Array of movies\r\rmyMovies = new Array ("movie1","movie2","movie3" ) ;

Good thing is : it works with any number of movies, and very very easily. :smiley: \r\rpom 0]

Version 3 complete !! You can grab it there membres.lycos.fr/museebra…rkshop.zip

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.\r\rThanks,\rMatt

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 ?? :smiley: \r\rpom 0]