# \[FMX\] Fading in dynamically loaded pictures

**URL:** <https://forum.kirupa.com/t/fmx-fading-in-dynamically-loaded-pictures/18213>\
**Category:** flash\
**Created:** [April 14, 2003, 4:41pm UTC](https://forum.kirupa.com/t/fmx-fading-in-dynamically-loaded-pictures/18213 "2003-04-14T16:41:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![elmago](https://avatars.discourse-cdn.com/v4/letter/e/848f3c/32.png) [@elmago](https://forum.kirupa.com/u/elmago)\
**Post date:** [April 14, 2003, 4:41pm UTC](https://forum.kirupa.com/t/fmx-fading-in-dynamically-loaded-pictures/18213/1 "2003-04-14T16:41:54Z")

</div>

Hi

Im making a site where I at the main frame load in a movie at a higher level. In this loaded movie I load in pictures dynamically with a function I use together with setInterval. I feel its a little bit anoying everytime a pic loads because it blinks. Is there maybe a smart way of fading the pictures in and out? I now it takes a lot of computer power using \_alpha, and because I load in the pics I cant use tweening. Any suggestions?

thanks

Armin

---

<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:** [April 17, 2003, 1:59am UTC](https://forum.kirupa.com/t/fmx-fading-in-dynamically-loaded-pictures/18213/2 "2003-04-17T01:59:50Z")

</div>

Hi, try this code, it is from Mx tutorials.  
buttons are: next & back  
Mc for pic is : square

//initialize variables and properties  
square.\_alpha = 0;  
whichPic = 1;  
//initiate change to new image when buttons are clicked  
next.onPress = function() {  
if (whichPic\<5 && !fadeIn && !fadeOut) {  
fadeOut = true;  
whichpic++;  
input = whichPic;  
}  
};  
back.onPress = function() {  
if (whichPic\>1 && !fadeIn && !fadeOut) {  
fadeOut = true;  
whichpic–;  
input = whichPic;  
}  
};  
\_root.onEnterFrame = function() {  
// when a new Photo is selected, fade out, load new image, and fade in  
if (square.\_alpha\>10 && fadeOut) {  
square.\_alpha -= 10;  
}  
if (square.\_alpha\<10) {  
loadMovie("…/images/image"+whichPic+".jpg", “square”);  
fadeOut = false;  
fadeIn = true;  
}  
if (square.\_alpha\<100 && fadeIn && !fadeOut) {  
square.\_alpha += 10;  
} else {  
fadeIn = false;  
}  
// limit input field  
if (input\>5) {  
input = 5;  
}  
// initiate change to new image when Enter key is pressed  
if (Key.isDown(Key.ENTER)) {  
fadeOut = true;  
whichpic = input;  
}  
};  
// if a number is entered in the input field but Enter is not pressed, change  
// back to current Photo number when clicking anywhere else  
inputField.onKillFocus = function() {  
input = whichPic;  
};

Not mine , but works well.  
I guess u can put preloaders on & convert to swf, the load swf instead of jpg… hope this not 2 stoopid. :nerd:

---

<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:** [April 17, 2003, 8:42am UTC](https://forum.kirupa.com/t/fmx-fading-in-dynamically-loaded-pictures/18213/3 "2003-04-17T08:42:51Z")

</div>

Thank you… I will try it out 🙂

Armin

---

<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:** [April 17, 2003, 9:35am UTC](https://forum.kirupa.com/t/fmx-fading-in-dynamically-loaded-pictures/18213/4 "2003-04-17T09:35:27Z")

</div>

No probs, just remember 2 set the path for ur images ie  
loadMovie("…/images/image"+whichPic+".jpg", “square”);

in this case the folder images is outside the current folder.

good luck!

:beam:
