Forum Moderators: open

Message Too Old, No Replies

Actionscript Pictures Fading

How can I get dynamically loading pics to fade in and out?

         

coertli

4:31 pm on Mar 1, 2006 (gmt 0)

10+ Year Member



So I have a site whose owner wants pitcures fading in and out on the main page. I have the code that loads the pictures and changes them every 5 seconds, but it is a quick change. How could I fade one picture in while fading another one out? Thanks for the help, and here is my code thus far:

Code:
_root.createEmptyMovieClip("pload",1);
//**************************************
//Load XML File
//**************************************
pArray=new Array();
my_xml=new XML();
my_xml.ignoreWhite=true;
my_xml.onLoad = function(success){
if(success){
for(var i=0; i<this.firstChild.childNodes.length; i++){
pArray_l = this.firstChild.childNodes.length;
pArray.push(this.firstChild.childNodes[i].attributes.pic);
}
}
load_home();
};
my_xml.load("pic.xml");
//**************************************
//Load Function Definition
//**************************************
function load_home(){
if(delay){
clearInterval(delay);
}
var j=Math.floor(Math.random()*pArray_l);
pload._x=0;
pload._y=0;
pload.loadMovie(pArray[j]);
delay=setInterval(load_home,5000);
}

coertli

9:57 pm on Mar 1, 2006 (gmt 0)

10+ Year Member



got it:

stop();
_root.createEmptyMovieClip("pload",1);
_root.createEmptyMovieClip("pload2",2);
//**************************************
//Preloader
//**************************************
preload= new MovieClipLoader();
//**************************************
//Load XML File
//**************************************
pArray=new Array();
my_xml=new XML();
my_xml.ignoreWhite=true;
my_xml.onLoad = function(success){
if(success){
for(var i=0; i<this.firstChild.childNodes.length; i++){
pArray_l = this.firstChild.childNodes.length;
pArray.push(this.firstChild.childNodes[i].attributes.pic);
}
}
load_home();
};
my_xml.load("pic.xml");
//**************************************
//Function Definitions
//**************************************
function load_home(){
if(delay){
clearInterval(delay);
}
pload.swapDepths(pload2);
var j=Math.floor(Math.random()*pArray_l);
pload._x=0;
pload._y=0;
pload.loadMovie(pArray[j]);
fadeIn(pload);
delay2=setInterval(load_home2,5000);
}

function load_home2(){
clearInterval(delay2);
pload.swapDepths(pload2);
fadeOut(pload);
var k=Math.floor(Math.random()*pArray_l);
pload2._x=0;
pload2._y=0;
pload2.loadMovie(pArray[k]);
fadeIn(pload2);
delay=setInterval(load_home,5000);
}

function fadeIn(movie){
movie._alpha=0;
_root.onEnterFrame=function(){
movie._alpha+=1;
if(movie._alpha>99){
movie._alpha=100;
delete _root.onEnterFrame;
}
}
}

function fadeOut(movie){
movie._alpha=100;
_root.onEnterFrame=function(){
movie._alpha-=1;
if(movie._alpha<2){
movie._alpha=0;
delete _root.onEnterFrame;
}
}
}