Whats a better way to remove an old image or an image that is not there at all?
I am working with this XML slideshow and I have tweaked it the way I want, except the first image that loads doesn’t disappear. How can I make this statement better? I’ve tried if (previous || imgHolder.numChildren > 0 ) as well and didn’t work. Any help?
package
{
import flash.display.MovieClip;
import com.greensock.*;
import com.greensock.loading.*;
import com.greensock.events.LoaderEvent;
import com.greensock.loading.display.*;
public class Main extends MovieClip
{
var xml:XMLLoader;
var images:Array;
var current:int = 0;
var previous:Number;
public function Main()
{
init();
}
private function init()
{
LoaderMax.activate([ImageLoader]);
xml = new XMLLoader("xml/gallery.xml",{name:"loader",onComplete:onXmlLoaded});
xml.load();
}
function onXmlLoaded(e:LoaderEvent)
{
images = LoaderMax.getContent("loader");
nextImage(); //nextImage can use image var
}
private function nextImage()
{
TweenLite.from(images[current],1,{alpha:0, onStart:currentImage, onComplete: updateImage});
}
private function currentImage():void
{
imgHolder.addChild(images[current]);
}
private function updateImage()
{
if (previous)
{
imgHolder.removeChild(images[previous]);
}
previous = current;
if (current < images.length - 1)
{
current++;
} else
{
current = 0;
}
TweenLite.delayedCall(2, nextImage);
}
}
}
You could manipulate the contents of the Array to keep track of your current and previous slide index. The first in the Array is your current slide and the last is the previous slide. Like you suggested a
numChildrencheck on yourimgHolderis a good way to check if there is something to remove.