AS3 Many tweening problems

Tag: actionscript-3 , tween Author: nmg080623 Date: 2011-10-23

I am having huge problems with AS3 and the tweening class. It just stops for no apparent reason...

My code is a menu of side panels that slide in-and-out when the user clicks the tabs.

It looks as follows:

var mainContent1X:Tween = new Tween(MainContent1, "x", Strong.easeOut, MainContent1.x, 325, 1, true);
var MainContent2X:Tween = new Tween(MainContent2, "x", Strong.easeOut, MainContent2.x, 1750, 1, true);
var mainContent3X:Tween = new Tween(MainContent3, "x", Strong.easeOut, MainContent3.x, 1750, 1, true);
var MainContent4X:Tween = new Tween(MainContent4, "x", Strong.easeOut, MainContent4.x, 1750, 1, true);
var mainContent5X:Tween = new Tween(MainContent5, "x", Strong.easeOut, MainContent5.x, 1750, 1, true);
var MainContent6X:Tween = new Tween(MainContent6, "x", Strong.easeOut, MainContent6.x, 1750, 1, true);

It just stops for no reason at all like the code isn't being executed. Sometimes only one tween happens and the others don't. Sometimes it works the way I want it to!!! I can't figure out why this is happening, I am relatively new to AS3, I'll appreciate any help.

Regards Luben

Best Answer

I assume its a lifetime problem of your variables. If your tween variables are only in local scope of a function, at the end of that function they are lost and so your Tweens.

Make them class variables or even better, use Tweener.


Along with tweener I've enjoyed using TweenMax

Other Answer1

Thanks Daniel,

I declared the variables outside the function and all is fine. It seems that the garbage collector was clearing them at the wrong time. The code looks as follows now:

var mainContent1X:Tween;

function name() {
mainContent1X = new Tween(MainContent1, "x", Strong.easeOut, MainContent1.x, 325, 1, true);

I'll look into Tweener/TweenMax although I'm hesitant about using 3rd party software.

Thanks again, Luben