Jump to content
Search Community

xml slideshow with timelinemax

chefkeifer test
Moderator Tag

Recommended Posts

I am having an issue of getting images from an xml to scroll through...on my local machine it does nothing but show one pic and then nothing after that..but for some reason out on the web it scrolls through the pics but at lightning speed and when it gets to the end it stops..it acts like it does not see the timeline at all.

 

here is my code...

import com.greensock.*; 
import com.greensock.plugins.*;
import com.greensock.easing.*;
//*****====================================================*****


function XMLLoaded(event:Event):void{
 xml = new XML(event.target.data);
 for each(var img in xml.image){
   var url:String = img.@url;
   var request:URLRequest = new URLRequest(url);
   var loader:Loader = new Loader();
   loader.load(request);
   addChild(loader);
var picScroll:TimelineMax = new TimelineMax({repeat:2});
	picScroll.append(TweenMax.to(loader, 0, {x:-250,y:-125, alpha:0}));
	picScroll.append(TweenMax.to(loader, .5, {alpha:1}));
	picScroll.append(TweenMax.to(loader, 2, {alpha:0}));
 }
}
//*****====================================================*****
var xml:XML;
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("xml/gallery.xml");
loader.addEventListener("complete", XMLLoaded);
loader.load(request);

Link to comment
Share on other sites

There are several problems I see right away:

 

1) You are creating a new TimelineMax for each image - didn't you want them one-after-the-other in the same TimelineMax? If so, create your TimelineMax and then do all of your append()s to that same instance. Otherwise all the timelines will play simultaneously.

 

2) By default, tweens with a duration of 0 are rendered immediately - if you want them to wait until the tween gets fired off in the timeline, set immediateRender:false in that tween's vars object.

 

3) You're not giving your images any time to load - you're starting the animation right away. What if the first one takes 5 seconds to load? The animation will have already completed by then. You should pause() the TimelineMax initially and set up a listener for the COMPLETE event of the Loader(s) and then play() your TimelineMax at that point.

Link to comment
Share on other sites

forgive me for my ignorance

 

isnt there a event listener for the loader right here

loader.addEventListener("complete", XMLLoaded);

 

so is the for each statement the issue?

function XMLLoaded(event:Event):void{
 xml = new XML(event.target.data);
 for each(var img in xml.image){
   var url:String = img.@url;
   var request:URLRequest = new URLRequest(url);
   var loader:Loader = new Loader();
   loader.load(request);
   addChild(loader);
 }
}

 

is there another way to bring in images via xml...i didn't think it would be that hard...

 

this code brings errors

import com.greensock.*; 
import com.greensock.plugins.*;
import com.greensock.easing.*;
//*****====================================================*****
var picScroll:TimelineMax = new TimelineMax({paused:true});
picScroll.append(TweenMax.to(loader, 0, {x:-250,y:-125, alpha:0}));
picScroll.append(TweenMax.to(loader, .5, {alpha:1}));
picScroll.append(TweenMax.to(loader, 2, {alpha:0}));
//*****====================================================*****

function XMLLoaded(event:Event):void{
 xml = new XML(event.target.data);
 for each(var img in xml.image){
   var url:String = img.@url;
   var request:URLRequest = new URLRequest(url);
   var loader:Loader = new Loader();
   loader.load(request);
   addChild(loader);
 }
}
//*****====================================================*****
var xml:XML;
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("xml/gallery.xml");
loader.addEventListener("complete", XMLLoaded);
loader.load(request);

Link to comment
Share on other sites

Your event listener was just for the XML which is completely separate from loading the actual images. The XML just tells you the URLs at which the images are stored.

 

Your code would look more like this (untested):

 

var picScroll:TimelineMax = new TimelineMax({repeat:2, paused:true});

function XMLLoaded(event:Event):void{	
 xml = new XML(event.target.data);
 var addedListener:Boolean = false;
 for each(var img in xml.image){
var url:String = img.@url;
var request:URLRequest = new URLRequest(url);
var loader:Loader = new Loader();
loader.x = -250;
loader.y = -125;
loader.alpha = 0;
loader.load(request);
addChild(loader);
picScroll.append(TweenMax.to(loader, 0.5, {alpha:1}));
picScroll.append(TweenMax.to(loader, 0.5, {alpha:0}), 2);
if (!addedListener) {
	loader.addEventListener(Event.COMPLETE, onFirstImageLoad);
	addedListener = true;
}
 }
}

function onFirstImageLoad(event:Event):void {
picScroll.play();
}

//*****====================================================*****
var xml:XML;
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("xml/gallery.xml");
loader.addEventListener("complete", XMLLoaded);
loader.load(request);

 

That only waits for the first image to load, so you may want to adjust the code so that it waits for them all to load or implements a preloader if/when the current image isn't loaded yet, etc.

Link to comment
Share on other sites

it still flies through the animation of fading in and out when testing on the web...but locally it shows nothing...I am not understanding that one...

 

here is a link to the actual gallery so you could see what is happening

http://www.thedepotgibsonmill.com

 

click on rent space

 

click more under the number "3" and you can see what i am talking about...

 

i know your busy and I appreciate your help

Link to comment
Share on other sites

i have watched the video...i loved it..I am looking forward to more...

 

i have attached the fla..not sure if that will help...since the other fla was pretty the same thing, i just took out the one movie clip that had the slideshow in it...

 

the xml file is pretty much straight forward

 

<?xml version="1.0" encoding="utf-8"?>







 

I did notice that nothing at all was showing, like you said...I do not get any errors just nothing shows up...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...