Hey all,
I have a slide show script, which works, but as of now, the image will completely fade out before the next one fades in.
What I want is for the next image to start fading in before the previous image completely fades out. Any help would be great…it’s got to be a simple fix…
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
var transition_time:Number = 2;
var displaying_time:Number = 3;
var timer_tween:Tween;
var alpha_tween:Tween;
var index:int = 0;
var is_picture_loaded:Boolean;
var is_next_transition_ready:Boolean = true;
var picture_holder:Sprite = new Sprite();
addChild(picture_holder);
picture_holder.x=8;
picture_holder.y=80;
var xml_data:XML;
var array_of_picture:Array = new Array();
var request_xml:URLRequest = new URLRequest("slideShow.xml");
var slideShowLoader:URLLoader = new URLLoader();
var request_picture:URLRequest;
var picture_loader:Loader;
slideShowLoader.addEventListener(Event.COMPLETE, completeHandler);
function completeHandler(e:Event):void{
xml_data = new XML(slideShowLoader.data);
for(var i:int = 0; i<xml_data.children().length(); i++){
array_of_picture.push(xml_data.child(i));
}
request_xml = null;
loader = null;
start_slide_show();
}
slideShowLoader.load(request_xml);
function start_slide_show():void{
if(index == array_of_picture.length){index = 0;}
request_picture = new URLRequest(array_of_picture[index]);
picture_loader = new Loader();
picture_loader.contentLoaderInfo.addEventListener(Event.INIT, loader_Handler);
picture_loader.load(request_picture);
index++;
}
function loader_Handler(e:Event):void{
e.target.content.visible = false;
picture_holder.addChild(e.target.content);
is_picture_loaded = true;
if(is_next_transition_ready){
var last_child:int = picture_holder.numChildren-1;
start_transition(picture_holder.getChildAt(last_child));
}
}
function start_transition(target:DisplayObject):void{
picture_holder.alpha=1;
is_next_transition_ready = false;
is_picture_loaded = false;
target.visible = true;
target.alpha = 0;
start_slide_show();
alpha_tween = new Tween(target, "alpha", null, 0, 1, transition_time, true)
alpha_tween.addEventListener(TweenEvent.MOTION_FINISH, start_timer);
}
function start_timer(e:TweenEvent):void{
Tweener.addTween (picture_holder, {alpha:0, time:2, delay:5, transition:"easeInOutExpo"});
var count:Number = 0;
timer_tween = new Tween(this, "count", null, 0, 1, displaying_time, true)
timer_tween.addEventListener(TweenEvent.MOTION_FINISH, remove_picture);
}
function remove_picture(e:TweenEvent):void{
if(picture_holder.numChildren>1){picture_holder.removeChildAt(0)}
timer_tween.removeEventListener(TweenEvent.MOTION_FINISH, remove_picture);
is_next_transition_ready = true;
if(is_picture_loaded){
var last_child:int = picture_holder.numChildren-1;
start_transition(picture_holder.getChildAt(last_child))
}
}
btw, if any of you have an idea to simplify this code, that would be great too.
Thanks
7