AS2 slideshow previous btn issue
- cosmic_billion
- Newbie


- Joined: Nov 05, 2009
- Posts: 14
- Loc: Amsterdam, the Netherlands
- Status: Offline
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.
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});
*/}
Cheers
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});
*/}
- 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});
- */}
Cheers
- Anonymous
- Bot


- Joined: 25 Feb 2008
- Posts: ?
- Loc: Ozzuland
- Status: Online
March 12th, 2012, 3:32 am
- ScottG
- Proficient


- Joined: Jul 06, 2010
- Posts: 265
- Status: Online
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.
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.
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});
}
/*
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});
}
- 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});
- }
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.
Page 1 of 1
To Reply to this topic you need to LOGIN or REGISTER. It is free.
Post Information
- Total Posts in this topic: 3 posts
- Users browsing this forum: No registered users and 54 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
