# Fading one jpeg in on top of another on(press)

**URL:** https://forum.kirupa.com/t/fading-one-jpeg-in-on-top-of-another-on-press/63225
**Category:** flash
**Created:** [September 4, 2004, 1:31am UTC](https://forum.kirupa.com/t/fading-one-jpeg-in-on-top-of-another-on-press/63225 "2004-09-04T01:31:22Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![3dron](https://avatars.discourse-cdn.com/v4/letter/3/2acd7d/32.png) [@3dron](https://forum.kirupa.com/u/3dron)
#### Post date: [September 4, 2004, 1:31am UTC](https://forum.kirupa.com/t/fading-one-jpeg-in-on-top-of-another-on-press/63225/1 "2004-09-04T01:31:22Z")

</div>

I have looked all over this forum and can’t find what I am looking for (though undoubtedly someone will point me to another thread.)

I have a dozen buttons of materials options. When the user hits one I want an external jpeg to fade into a fix position mc, over the previous jpeg their. And as the user keeps hitting the buttons jpeg upon jpeg will fade in on top.

I am using

init = function () {  
Img1.myContainer = Img1.createEmptyMovieClip(“cont”, 1);  
Img1.myContainer.loadMovie(\_global.imagename);  
};

and

on(press) {  
\_global.imagename = “myImage.jpg”;  
init();  
}  
.

But this just pops the next image in with a gap in between.

Don’t I have to create movieclips one level higher than the previous, then after fade up of alpha, unload previous mc. I don’t want dozens of mcs to just keep layering one on another?

A preload would be nice for the future (without a status message.) But for now the app runs locally.

Thanks for any help

Ron R. Jr.

P.S. I tried using [http://www.kirupaforum.com/forums/showthread.php?s=&threadid=33872](http://www.kirupaforum.com/forums/showthread.php?s=&threadid=33872) but I am not sure if it does what I need as I could not figure out how to point the functions to an external mc. I replaced all instances of “this” text with “Img1” to point them to my \_root.Img1 mc but the fadeIn function did not work.

---

<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: [September 4, 2004, 7:07am UTC](https://forum.kirupa.com/t/fading-one-jpeg-in-on-top-of-another-on-press/63225/2 "2004-09-04T07:07:40Z")

</div>

create a moviclip oMovie  
in that put 2 movieclips (imgHolder1, imgHolder2) in different levels.  
set \_alpha of both to 0 so now both are invisible.  
in the main timeline  
imgHolder1.loadMovie(“1.jpg”);  
imgHolder1.\_alpha=100;  
displayedimage=“imgHolder1”;

now when a button is clicked,  
if(displayedimage==“imgHolder1”) {  
displayedimage=“imgHolder2”;  
}  
this[displayedimage].loadMovie(“2.jpg”);  
this[displayedimage].swapdepths(1000);  
this[displayedimage].fadeIn

see what i mean ?

---

<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: [September 4, 2004, 8:09am UTC](https://forum.kirupa.com/t/fading-one-jpeg-in-on-top-of-another-on-press/63225/3 "2004-09-04T08:09:02Z")

</div>

this[displayedimage].fadeIn

where is the fadeIn function?

If I set the alphas to 100 then I get the pictures switching with out gaps. If I add:

if(displayedimage==“imgHolder1”) {  
displayedimage=“imgHolder2”;  
} else {displayedimage=“imgHolder1”;}

But now I need the fadeIn effect.

Thanks for fast reply. I know I’m close.

Ron R. Jr.

Is this close???

function fadeIn () {  
if (this[displayedimage].\_alpha \< 100) {  
this[displayedimage].\_alpha += 1  
//The higher the number the faster it fades  
} else {  
clearInterval (time)  
}  
}  
time = setInterval (fadeIn, 50)

---

<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: [September 4, 2004, 9:40am UTC](https://forum.kirupa.com/t/fading-one-jpeg-in-on-top-of-another-on-press/63225/4 "2004-09-04T09:40:28Z")

</div>

maybe or you can use tweening inside the imgHolder movieclips.

might be easier.

---

<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: [September 16, 2004, 10:30pm UTC](https://forum.kirupa.com/t/fading-one-jpeg-in-on-top-of-another-on-press/63225/5 "2004-09-16T22:30:33Z")

</div>

I am attempting to do something very similar but am having trouble getting it to work. If you did manage it and have the code or file on hand it would be much appreciated if I could take a look.  
Thanks  
erok
