# Actionscript with alpha

**URL:** <https://forum.kirupa.com/t/actionscript-with-alpha/2556>\
**Category:** flash\
**Created:** [May 29, 2002, 4:52pm UTC](https://forum.kirupa.com/t/actionscript-with-alpha/2556 "2002-05-29T16:52:01Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 29, 2002, 4:52pm UTC](https://forum.kirupa.com/t/actionscript-with-alpha/2556/1 "2002-05-29T16:52:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 29, 2002, 5:23pm UTC](https://forum.kirupa.com/t/actionscript-with-alpha/2556/2 "2002-05-29T17:23:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 29, 2002, 5:35pm UTC](https://forum.kirupa.com/t/actionscript-with-alpha/2556/3 "2002-05-29T17:35:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 29, 2002, 5:55pm UTC](https://forum.kirupa.com/t/actionscript-with-alpha/2556/4 "2002-05-29T17:55:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 29, 2002, 8:08pm UTC](https://forum.kirupa.com/t/actionscript-with-alpha/2556/5 "2002-05-29T20:08:03Z")

</div>

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\r[www.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](http://www.msyverjensen.0catch.com/workshop_5.fla)\r\rThanks\rMatt

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 5, 2002, 3:20pm UTC](https://forum.kirupa.com/t/actionscript-with-alpha/2556/6 "2002-06-05T15:20:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 5, 2002, 4:50pm UTC](https://forum.kirupa.com/t/actionscript-with-alpha/2556/7 "2002-06-05T16:50:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 5, 2002, 5:02pm UTC](https://forum.kirupa.com/t/actionscript-with-alpha/2556/8 "2002-06-05T17:02:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 5, 2002, 5:41pm UTC](https://forum.kirupa.com/t/actionscript-with-alpha/2556/9 "2002-06-05T17:41:40Z")

</div>

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 :

```auto
  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]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 5, 2002, 7:02pm UTC](https://forum.kirupa.com/t/actionscript-with-alpha/2556/10 "2002-06-05T19:02:07Z")

</div>

Version 2.0

```auto
 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. 😃 \r\rpom 0]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 5, 2002, 10:09pm UTC](https://forum.kirupa.com/t/actionscript-with-alpha/2556/11 "2002-06-05T22:09:35Z")

</div>

Version 3 complete !! You can grab it there [membres.lycos.fr/museebra…rkshop.zip](http://membres.lycos.fr/museebranly/flash/Workshop.zip)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 9, 2002, 8:15pm UTC](https://forum.kirupa.com/t/actionscript-with-alpha/2556/12 "2002-06-09T20:15:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 9, 2002, 8:50pm UTC](https://forum.kirupa.com/t/actionscript-with-alpha/2556/13 "2002-06-09T20:50:55Z")

</div>

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