Jump to content
Search Community

problems with code for Sliding Movieclip

kirks61 test
Moderator Tag

Recommended Posts

I created an AS2 sliding movieclip that uses buttons to slide a multi-pane movieclip left or right 245 pixels at at time. I'm having trouble getting the buttons to recognize that the movieclip has moved over (see that the _x position has changed) so that it knows to move the movieclip to the next _x position using the AS2 code below:

 

var xpos:Number;
xpos = mcSlider2._x;
//trace(xpos);

ArrowLeft_mc.onRelease=function(){
switch (xpos) {
	case -245: 
		TweenLite.to(mcSlider2, 1, {_x:0}); 
		break;
	case -490: 
		TweenLite.to(mcSlider2, 1, {_x:-245}); 
		break;
	case -735: 
		TweenLite.to(mcSlider2, 1, {_x:-490}); 
		break;
	default: ;
}
}
ArrowRight_mc.onRelease=function(){

switch (xpos) {
	case 0: 
		TweenLite.to(mcSlider2, 1, {_x:-245}); 
		break;
	case -245: 
		TweenLite.to(mcSlider2, 1, {_x:-490}); 
		break;
	case -490: 
		TweenLite.to(mcSlider2, 1, {_x:-735}); 
		break;
	default: ;
}
}

 

ArrowRight_mc works only when mcSlider2 when _x is 0.

 

Previously, I used a statement that moved the movieclip left or right 245 pixels at at time but that caused a lot of problems although it worked.

 

Any idea why this isn't working? Do I need to use setInterval? If so, how would I incorporate that without interfering with Tweenlite?

Link to comment
Share on other sites

from what I can tell you only set the xpos variable ONCE and that value is and will always be what the INITIAL value of mcSlider2._x, which I'm assuming is 0 when the variable is created.

 

in your switch statement you need to do:

 

ArrowLeft_mc.onRelease=function(){
//reset xpos EACH time the button is released
xpos = mcSlider2._x;
  switch (xpos) {
     case -245: 
        TweenLite.to(mcSlider2, 1, {_x:0}); 
        break;
     case -490: 
        TweenLite.to(mcSlider2, 1, {_x:-245}); 
        break;
     case -735: 
        TweenLite.to(mcSlider2, 1, {_x:-490}); 
        break;
     default: ;
  }
}

Link to comment
Share on other sites

I realized the problem and fixed it not long after posting this request. Actually, what I did was:

ArrowLeft_mc.onRelease=function(){
switch (xpos) {
	case -245:
		TweenLite.to(mcSlider2, 1, {_x:0}); 
		xpos = 0;
		break;
	case -490: 
		TweenLite.to(mcSlider2, 1, {_x:-245}); 
		xpos = -245;
		break;
	case -735:
		TweenLite.to(mcSlider2, 1, {_x:-490}); 
		xpos = -490;
		break;
	case -980: 
		TweenLite.to(mcSlider2, 1, {_x:-735});
		xpos = -735;
		break;
	default: ;
}
}

 

 

ks

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...