# Need help with the tween class

**URL:** https://forum.kirupa.com/t/need-help-with-the-tween-class/240174
**Category:** Uncategorized
**Created:** [September 30, 2007, 10:12am UTC](https://forum.kirupa.com/t/need-help-with-the-tween-class/240174 "2007-09-30T10:12:34Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![ediblecastle](https://avatars.discourse-cdn.com/v4/letter/e/ac91a4/32.png) [@ediblecastle](https://forum.kirupa.com/u/ediblecastle)
#### Post date: [September 30, 2007, 10:12am UTC](https://forum.kirupa.com/t/need-help-with-the-tween-class/240174/1 "2007-09-30T10:12:34Z")

</div>

I’ve been making a little scrolling panel for a website. It’s a product panel where the user can scroll through the items. You can see how far I’ve got with it here:

[http://willarbuckle.com/junk/shop.html](http://willarbuckle.com/junk/shop.html)

But there’s a problem. Items, by which i mean the red squares, should always come to a rest, central on the panel. When the arrows are clicked in succession before the items come to a rest the centralisation is thrown off.

This is because the code is telling the movieclip to move by 130 pixels when the arrows are clicked. So if the movieclip hasnt managed to move the full 130 pixels before the user clicks again… we get the MC not moving far enough.

Here’s the code I have:

import mx.transitions.Tween;  
import mx.transitions.easing.\*;

var nProducts:Number = 6;  
var counter:Number = 1;

if (counter == 1){  
mcPrevButton.\_visible = false;  
} else {  
mcPrevButton.\_visible = true;  
}

if (counter == nProducts){  
mcNextButton.\_visible = false;  
} else {  
mcNextButton.\_visible = true;  
}

mcNextButton.onRelease = function():Void{  
var prodMovement:Tween = new Tween(mcProducts, “\_x”, Elastic.easeOut, mcProducts.\_x, mcProducts.\_x+130, 90, false);

counter++;

if (counter == 1){  
mcPrevButton.\_visible = false;  
} else {  
mcPrevButton.\_visible = true;  
}

if (counter == nProducts){  
mcNextButton.\_visible = false;  
} else {  
mcNextButton.\_visible = true;  
}  
};

mcPrevButton.onRelease = function():Void{  
var prodMovement:Tween = new Tween(mcProducts, “\_x”, Elastic.easeOut, mcProducts.\_x, mcProducts.\_x-130, 90, false);

counter–;

if (counter == 1){  
mcPrevButton.\_visible = false;  
} else {  
mcPrevButton.\_visible = true;  
}

if (counter == nProducts){  
mcNextButton.\_visible = false;  
} else {  
mcNextButton.\_visible = true;  
}  
};

If anyone wants to have a look at the flash doc:  
[http://willarbuckle.com/junk/shop.fla](http://willarbuckle.com/junk/shop.fla)

Any help would be really really appreciated, any ideas?  
thanks guys.

-Will
