Question

I created sort of a nifty image scroller that scrolls a movieclip right or left based on a relative tween. I would however like to add an if statement or something, so that when the movieclip gets to a certain position, either the left direction arrow is disabled or the right direction arrow is disabled. Here is the code I have so far:

import flash.display.MovieClip;
import flash.events.MouseEvent;
import com.greensock.*;
import com.greensock.easing.*;

function init():void{
    TweenLite.to(products_mc, 1, {x:696, alpha:1});
}

init();
checkPositionR();


function productsLeft(events:MouseEvent):void
{
    TweenLite.to(products_mc, .75, {x:"-255"});
    arrowR_btn.visible = true;
    arrowR_btn.buttonMode = true;
    checkPositionL();

}

function productsRight(events:MouseEvent):void
{
    TweenLite.to(products_mc, .75, {x:"255"});
    arrowL_btn.visible = true;
    arrowL_btn.buttonMode = true;
    checkPositionR();

}

function checkPositionR():void
{
if (products_mc.x = 696) {
    arrowR_btn.visible = false;
    arrowR_btn.buttonMode = false;
}

}

function checkPositionL():void
{
if (products_mc.x = -1086) {
    arrowL_btn.visible = false;
    arrowL_btn.buttonMode = false;
}

}
arrowL_btn.buttonMode = true;
arrowL_btn.addEventListener(MouseEvent.CLICK, productsLeft);

arrowR_btn.buttonMode = true;
arrowR_btn.addEventListener(MouseEvent.CLICK, productsRight);

arrowL_btn.doubleClickEnabled = true;
arrowR_btn.doubleClickEnabled = true; 

arrowL_btn.addEventListener(MouseEvent.DOUBLE_CLICK, doubleClickHandler, false); 
arrowR_btn.addEventListener(MouseEvent.DOUBLE_CLICK, doubleClickHandler, false); 

function doubleClickHandler(evt:MouseEvent):void 
 {
  evt.stopPropagation();
 }

If you remove the checkPositionR() and checkPositionL() functions from the productsRight() and productsLeft() functions, you'll see this works ok, however then it ignores the toggle the button off. Basically this is just scrolling a movie clip left or right and I want it to not be able to scroll beyond a certain point in either direction. (or loops)

Any ideas? Thanks!

(yes I could do this on the timeline alot easier but I think this cool be as scripted)

Was it helpful?

Solution 2

OK i found the perfect solution: http://www.flashuser.net/build-an-image-slideshow-in-flash

However now I'm wondering, if there a way to do this on multiple movieclips at once with one click?

OTHER TIPS

try using an if statement in productsRight/Left that will only run if the object's x value is with in a certain limit.

productsRight:

if(products_mc.x < 696){
    //your Code
}

productsLeft:

if(products_mc.x > -1086){
    //your Code
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top