Skip to main content
July 13, 2010
Question

Tweenlite: slideshow not "sliding"

  • July 13, 2010
  • 1 reply
  • 1726 views

Hello,

I've got a little problem with a slideshow I am modifying. Note that I am not the maker of it, but am adding stuff to the actual flash. I haven't changed it much but it won't "slide" anymore and I can't find why...

Here's the code:

------------------------------------------------------------------------------------------

import com.greensock.*;
import flash.net.URLRequest;
import flash.display.Stage;

var imageLoader:Loader = new Loader();
var imageLoader2:Loader = new Loader();
var myTween:TweenLite;
var myImages_array:Array = new Array;

var img = 0;
var ordre = 0;
var image_total = 0;

var transition = 0;
var musique = 0;
var duree = 0;
var site_root = "";

function load_xml():void
{                   
    var rnd = Math.floor(Math.random()*100000000);
    var url:String = root.loaderInfo.parameters.site_root + "services/slideshow.ashx?id=" + root.loaderInfo.parameters.sujet_no + "&rn=" + rnd;
    var loadit:URLLoader = new URLLoader();
    loadit.addEventListener(Event.COMPLETE, completeHandler);
    loadit.load(new URLRequest(url));
   
    function completeHandler(e:Event):void {
        var myXML:XML = new XML(e.target.data);
        var myOptions:XMLList = myXML.options.elements();
        var myImages:XMLList = myXML.images.elements();
       
        transition = myOptions[0].@["id"];
        musique = myOptions[1].@["id"];
        duree = myOptions[2].@["id"]; // in seconds
       
        for each(var image:XML in myImages)
        {
            myImages_array.push(image.@["path"]);
        }
       
        init_slideshow();
    }
}

function init_slideshow()
{
    image_total = myImages_array.length;
   
    load_image(imageLoader,img);
    load_image(imageLoader2,img+1);
    img = img + 1;
    animate_slideshow();
}

function animate_slideshow()
{
  if(ordre == 0)
  {
      myTween = new TweenLite(myLoader, 2, {alpha:0,delay:duree, onComplete:next_slide});
  }
  else
  {
      myTween = new TweenLite(myLoader2, 2, {alpha:0,delay:duree, onComplete:next_slide});
  }
}

function next_slide()
{
    if(img >= image_total-1)
    {
        img = -1;
    }
   
    if(ordre == 0)
    {
        setChildIndex(myLoader,0);
        setChildIndex(myLoader2,1);
       
        myLoader.alpha = 1;
        load_image(imageLoader,img+1);
        img = img + 1;

        ordre = 1;
    }
    else
    {
        setChildIndex(myLoader,1);
        setChildIndex(myLoader2,0);
       
        myLoader2.alpha = 1;
        load_image(imageLoader2,img+1);
        img = img + 1;

        ordre = 0;
    }

    animate_slideshow();
}

function load_image(myMc,img)
{
    myMc.unload();

    if(ordre == 0)
    {
        for(var i:uint = 0; i < myLoader.numChildren; i++){
           myLoader.removeChildAt(i);
        }
    }
    else
    {
        for(var z:uint = 0; z < myLoader2.numChildren; z++){
              myLoader2.removeChildAt(z);
        }
    }
   
    myMc.load(new URLRequest(root.loaderInfo.parameters.site_root + myImages_array[img]));
}

function hide_image()
{
    if(img == myImages_array.length - 1)
    {
        img = 0;
    }
    else
    {
        img = img + 1;
    }
   
    myTween = new TweenLite(myLoader, 5, {alpha:0,delay:duree, onComplete:load_image, onCompleteParams:[img]});
}

imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event){
  myLoader.addChild(e.target.content);
});

imageLoader2.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event){
  myLoader2.addChild(e.target.content);
});

myLoader.x = 0;
myLoader.y = 0;

myLoader2.x = 0;
myLoader2.y = 0;

load_xml();

stop();

------------------------------------------------------------------------------------------

So, from the XML, everything is loaded fine (I traced it) and I have all values. The slideshow starts (the first image appear) but it won't slide to the second one (or so on)... I guess there is a problem with the Tweenlite, but what?

Thanks for any help!

This topic has been closed for replies.

1 reply

July 13, 2010

Please ignore my precedent question, I found the problem. However, there is one thing that I should correct as soon as possible. The fact is that people can upload any image size for the slideshow, so it can be 100x100 then 1000x1000. The problem is when a small image is showing, the next (bigger) image will also show under. Before we were using always the same image size, but now, it's not like that anymore. Anyone got an idea to how make sure the next image doesn't show until it's time?

Inspiring
July 13, 2010

I'm not seeing your project but you can probably use a mask to show only what you want and hide everything else.