AS2 slideshow previous btn issue

  • cosmic_billion
  • Newbie
  • Newbie
  • User avatar
  • Posts: 14
  • Loc: Amsterdam, the Netherlands

Post 3+ Months Ago

Hello Ozzu people,

How is everybody? :)

There is a great Action Script 2/XML slideshow code I found through a link on Smashing Magazine, the reason I like it is because it had a nice little tween between images, but dun dun dun...

I have managed to insert a next, play and pause button but not the previous button function.

The prev_btn is supposed to call up the current image position - 1, the same way the next_btn calls the current image + 1. This makes sense but I getting confused with something..


Your help will be aprreciated.

Code: [ Select ]

import gs.*;
import gs.easing.*;


//---Load XML


var xmlPath = "photos.xml";
var photos_xml = new XML();
photos_xml.ignoreWhite = true;
var imageList:Array = new Array();
photos_xml.onLoad = function(success) {
    if (success) { // ----------- load successful
        // ----------- convert XML content to an array
        imageList = photos_xml.firstChild.childNodes;
        // ----------- Do some action once xml is loaded
        loadImage();
        // ----------- Do some action once xml is loaded
    } else {
        // ----------- problem loading, check path
        trace("Error loading photos_xml");
    }
}

//---Load Images


var currentImage:Number = 0;
var imageLoader:MovieClipLoader = new MovieClipLoader();
var loadListener:Object = new Object();

imageLoader.addListener(loadListener);

loadListener.onLoadInit = function(target_mc:MovieClip, httpStatus:Number):Void {
    TweenLite(dot)to(container_mc.background_mc, 1, {_width:target_mc._width + 20, _height:target_mc._height + 20, ease:Strong.easeOut});
    TweenLite(dot)to(container_mc.border_mc, 1, {_width:target_mc._width, _height:target_mc._height, ease:Strong.easeOut});
    TweenLite(dot)to(container_mc.mask_mc, 1, {_width:target_mc._width, _height:target_mc._height, ease:Strong.easeOut});
    
    // center content
    var clipXTarg = Math.round((Stage.width/2)-((target_mc._width+20)/2));
    var clipYTarg = Math.round((Stage.height/2)-((target_mc._height+20)/2));
    TweenLite(dot)to(container_mc, 1, {_x:clipXTarg, _y:clipYTarg, ease:Strong.easeOut});

    // find previous image
    if(currentImage == 0){
        var prevImgNum = imageList.length -1;
    }else{
        var prevImgNum = currentImage -1;
    }
    var prevImg = container_mc.pics_mc["pic"+prevImgNum];
    TweenLite(dot)to(prevImg, 1, {autoAlpha:0, onComplete:removePrevious});
}

loadListener.onLoadComplete = function(target_mc:MovieClip):Void {
    TweenLite(dot)to(target_mc, 1, {autoAlpha:100, delay:1});
    setTimer();
}


//---Functions List


function setTimer(){
    timer = setInterval(loadImage, 5000);
}

function removePrevious(){
    if(prevImg != undefined){
        removeMovieClip(prevImg);
    }
    
    
    // increment the current image
    if(currentImage < imageList.length -1){
        currentImage = currentImage + 1;
    }else{
        currentImage = 0;
    }
}

    //Load the next image automatically
function loadImage(){
    var loadURL = imageList[currentImage].attributes.imgurl;
    var targetClip = container_mc.pics_mc.createEmptyMovieClip("pic"+currentImage,container_mc.pics_mc.getNextHighestDepth());
    targetClip._alpha = 0;
    clearInterval(timer);


    
    // load the new image
    imageLoader.loadClip(loadURL,targetClip);
}
    //Load the next image if the button was pressed
function loadImagePrevious() {
    if(currentImage == 0){
        var prevImgNum = imageList.length -1;
        
        var loadURL = imageList[prevImg].attributes.imgurl;
        var targetClip = container_mc.pics_mc.createEmptyMovieClip("pic"+prevImg,container_mc.pics_mc.getNextHighestDepth());
        targetClip._alpha = 0;
        clearInterval(timer);
    
        // load the new image
        imageLoader.loadClip(loadURL,targetClip);
        
    }else{
        var prevImgNum = currentImage - 1;
        var loadURL = imageList[prevImg].attributes.imgurl;
        var targetClip = container_mc.pics_mc.createEmptyMovieClip("pic"+prevImg,container_mc.pics_mc.getNextHighestDepth());
        targetClip._alpha = 0;
        clearInterval(timer);
    
        // load the new image
        imageLoader.loadClip(loadURL,targetClip);
    }
}


//---On First Load

photos_xml.load(xmlPath);
stop();



//---Buttons


next_mc.onRelease = function() {
    clearInterval(timer);
    timer = setInterval(loadImage, 500);
    pause_mc._visible = true;
    play_mc._visible = false;
}

prev_mc.onRelease = function() {
    clearInterval(timer);
    ????
    pause_mc._visible = true;
    play_mc._visible = false;
    /*if(currentImage == 0){
        var prevImgNum = imageList.length -1;
    }else{
        var prevImgNum = currentImage - 1;
    }
    var prevImg = container_people_mc.pics_mc["pic"+currentImageNumber];
    TweenLite(dot)to(currentImage, 1, {autoAlpha:0, onComplete:removeCurrent});

*/}
  1. import gs.*;
  2. import gs.easing.*;
  3. //---Load XML
  4. var xmlPath = "photos.xml";
  5. var photos_xml = new XML();
  6. photos_xml.ignoreWhite = true;
  7. var imageList:Array = new Array();
  8. photos_xml.onLoad = function(success) {
  9.     if (success) { // ----------- load successful
  10.         // ----------- convert XML content to an array
  11.         imageList = photos_xml.firstChild.childNodes;
  12.         // ----------- Do some action once xml is loaded
  13.         loadImage();
  14.         // ----------- Do some action once xml is loaded
  15.     } else {
  16.         // ----------- problem loading, check path
  17.         trace("Error loading photos_xml");
  18.     }
  19. }
  20. //---Load Images
  21. var currentImage:Number = 0;
  22. var imageLoader:MovieClipLoader = new MovieClipLoader();
  23. var loadListener:Object = new Object();
  24. imageLoader.addListener(loadListener);
  25. loadListener.onLoadInit = function(target_mc:MovieClip, httpStatus:Number):Void {
  26.     TweenLite(dot)to(container_mc.background_mc, 1, {_width:target_mc._width + 20, _height:target_mc._height + 20, ease:Strong.easeOut});
  27.     TweenLite(dot)to(container_mc.border_mc, 1, {_width:target_mc._width, _height:target_mc._height, ease:Strong.easeOut});
  28.     TweenLite(dot)to(container_mc.mask_mc, 1, {_width:target_mc._width, _height:target_mc._height, ease:Strong.easeOut});
  29.     
  30.     // center content
  31.     var clipXTarg = Math.round((Stage.width/2)-((target_mc._width+20)/2));
  32.     var clipYTarg = Math.round((Stage.height/2)-((target_mc._height+20)/2));
  33.     TweenLite(dot)to(container_mc, 1, {_x:clipXTarg, _y:clipYTarg, ease:Strong.easeOut});
  34.     // find previous image
  35.     if(currentImage == 0){
  36.         var prevImgNum = imageList.length -1;
  37.     }else{
  38.         var prevImgNum = currentImage -1;
  39.     }
  40.     var prevImg = container_mc.pics_mc["pic"+prevImgNum];
  41.     TweenLite(dot)to(prevImg, 1, {autoAlpha:0, onComplete:removePrevious});
  42. }
  43. loadListener.onLoadComplete = function(target_mc:MovieClip):Void {
  44.     TweenLite(dot)to(target_mc, 1, {autoAlpha:100, delay:1});
  45.     setTimer();
  46. }
  47. //---Functions List
  48. function setTimer(){
  49.     timer = setInterval(loadImage, 5000);
  50. }
  51. function removePrevious(){
  52.     if(prevImg != undefined){
  53.         removeMovieClip(prevImg);
  54.     }
  55.     
  56.     
  57.     // increment the current image
  58.     if(currentImage < imageList.length -1){
  59.         currentImage = currentImage + 1;
  60.     }else{
  61.         currentImage = 0;
  62.     }
  63. }
  64.     //Load the next image automatically
  65. function loadImage(){
  66.     var loadURL = imageList[currentImage].attributes.imgurl;
  67.     var targetClip = container_mc.pics_mc.createEmptyMovieClip("pic"+currentImage,container_mc.pics_mc.getNextHighestDepth());
  68.     targetClip._alpha = 0;
  69.     clearInterval(timer);
  70.     
  71.     // load the new image
  72.     imageLoader.loadClip(loadURL,targetClip);
  73. }
  74.     //Load the next image if the button was pressed
  75. function loadImagePrevious() {
  76.     if(currentImage == 0){
  77.         var prevImgNum = imageList.length -1;
  78.         
  79.         var loadURL = imageList[prevImg].attributes.imgurl;
  80.         var targetClip = container_mc.pics_mc.createEmptyMovieClip("pic"+prevImg,container_mc.pics_mc.getNextHighestDepth());
  81.         targetClip._alpha = 0;
  82.         clearInterval(timer);
  83.     
  84.         // load the new image
  85.         imageLoader.loadClip(loadURL,targetClip);
  86.         
  87.     }else{
  88.         var prevImgNum = currentImage - 1;
  89.         var loadURL = imageList[prevImg].attributes.imgurl;
  90.         var targetClip = container_mc.pics_mc.createEmptyMovieClip("pic"+prevImg,container_mc.pics_mc.getNextHighestDepth());
  91.         targetClip._alpha = 0;
  92.         clearInterval(timer);
  93.     
  94.         // load the new image
  95.         imageLoader.loadClip(loadURL,targetClip);
  96.     }
  97. }
  98. //---On First Load
  99. photos_xml.load(xmlPath);
  100. stop();
  101. //---Buttons
  102. next_mc.onRelease = function() {
  103.     clearInterval(timer);
  104.     timer = setInterval(loadImage, 500);
  105.     pause_mc._visible = true;
  106.     play_mc._visible = false;
  107. }
  108. prev_mc.onRelease = function() {
  109.     clearInterval(timer);
  110.     ????
  111.     pause_mc._visible = true;
  112.     play_mc._visible = false;
  113.     /*if(currentImage == 0){
  114.         var prevImgNum = imageList.length -1;
  115.     }else{
  116.         var prevImgNum = currentImage - 1;
  117.     }
  118.     var prevImg = container_people_mc.pics_mc["pic"+currentImageNumber];
  119.     TweenLite(dot)to(currentImage, 1, {autoAlpha:0, onComplete:removeCurrent});
  120. */}



Cheers
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 477

Post 3+ Months Ago

Ok? .... As I'm looking at this code the part that dose all of the work always looks backward ... I'll explain ... the code below finds the movieclip the script created by taking the current image and taking away 1 also when the function removePrevious gets called also below it remove the previous image and adds to the current image.

ACTIONSCRIPT Code: [ Select ]
loadListener.onLoadInit = function(target_mc:MovieClip, httpStatus:Number):Void {
/*
I remove most of was not needed to show you
*/
    // find previous image
    if(currentImage == 0){
        var prevImgNum = imageList.length -1;
    }else{
        var prevImgNum = currentImage -1;
    }
    var prevImg = container_mc.pics_mc["pic"+prevImgNum];
    TweenLite(dot)to(prevImg, 1, {autoAlpha:0, onComplete:removePrevious});
}
 
  1. loadListener.onLoadInit = function(target_mc:MovieClip, httpStatus:Number):Void {
  2. /*
  3. I remove most of was not needed to show you
  4. */
  5.     // find previous image
  6.     if(currentImage == 0){
  7.         var prevImgNum = imageList.length -1;
  8.     }else{
  9.         var prevImgNum = currentImage -1;
  10.     }
  11.     var prevImg = container_mc.pics_mc["pic"+prevImgNum];
  12.     TweenLite(dot)to(prevImg, 1, {autoAlpha:0, onComplete:removePrevious});
  13. }
  14.  


The only thing I can think of with out completely changing the code is to reverse the imageList array and basically do a next image function like you did and setup a set interval to reverse it back. NOT pretty and not sure if it will work correctly with out actually testing it but it with out doing a recode on how the images switch its the best I can come up with at the moment.
  • cosmic_billion
  • Newbie
  • Newbie
  • User avatar
  • Posts: 14
  • Loc: Amsterdam, the Netherlands

Post 3+ Months Ago

Ya, no, its not working yet, its actually loading the next image..Hahaaaaa

Thanks for your response and effort ScottG!

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 15 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.