Skip to main content
Known Participant
January 25, 2010
Question

Edit tween insted of creating new instance?

  • January 25, 2010
  • 1 reply
  • 354 views

Hello, in my project i call the "animateLeft" function like 50 times, it makes a lot of tweens, but now it create new tweens every time the function is called, witch is not memory effective??

Are there a way to declar the tween once, "var cTween0:GTween = new GTween();" and then just edit the tween insted of creating a new one?

like

cTween0n(itemList[0],scrollSpeed,{x:itemList[0].startPoss -  itemList[0].width,scaleX:itemList[0].cScale,scaleY:itemList[0].cScale });

??

I cant get it to worke 😕😕

This is the code.

private function animateLeft(e:Event = null):void

{

var cTween0:GTween = new GTween(itemList[0],scrollSpeed,{x:itemList[0].startPoss -  itemList[0].width,scaleX:itemList[0].cScale,scaleY:itemList[0].cScale });

var cTween1:GTween = new GTween(itemList[1],scrollSpeed,{ x:itemList[0].startPoss,scaleX:itemList[0].cScale,scaleY:itemList[0].cScale});

var cTween2:GTween = new GTween(itemList[2],scrollSpeed,{ x:itemList[1-extraStep].startPoss,scaleX:itemList[1-extraStep].cScale,scaleY:itemList[1-extraStep].cScale });

var cTween3:GTween = new GTween(itemList[3],scrollSpeed,{ x:itemList[2-extraStep].startPoss,scaleX:itemList[2-extraStep].cScale,scaleY:itemList[2-extraStep].cScale });

var cTween4:GTween = new GTween(itemList[4],scrollSpeed,{ x:itemList[3-extraStep].startPoss,scaleX:itemList[3-extraStep].cScale,scaleY:itemList[3-extraStep].cScale });

var cTween5:GTween = new GTween(itemList[5],scrollSpeed,{ x:itemList[4-extraStep].startPoss,scaleX:itemList[4-extraStep].cScale,scaleY:itemList[4-extraStep].cScale});

var cTween6:GTween = new GTween(itemList[6],scrollSpeed,{ x:itemList[5-extraStep].startPoss,scaleX:itemList[5-extraStep].cScale,scaleY:itemList[5-extraStep].cScale});

var cTween7:GTween = new GTween(itemList[7],scrollSpeed,{ x:itemList[6-extraStep].startPoss,scaleX:itemList[6-extraStep].cScale,scaleY:itemList[6-extraStep].cScale});

var cTween8:GTween = new GTween(itemList[8],scrollSpeed,{ x:itemList[7-extraStep].startPoss,scaleX:itemList[7-extraStep].cScale,scaleY:itemList[7-extraStep].cScale});

}

thanks!

This topic has been closed for replies.

1 reply

January 25, 2010

Not sure about GTween - is that Grant Skinners? You should switch to TweenLite if it is, he abandoned GTween and is now helping on TweenLite. Anyway, I can say with TweenLite when you create a tween for the same object it is automatically overwritten unless you tell it not to be.

For what you showed here, it would only take a couple of minutes to make the switch:

var cTween0:GTween = new GTween(itemList[0],scrollSpeed,{x:itemList[0].startPoss -  itemList[0].width,scaleX:itemList[0].cScale,scaleY:itemList[0].cScale });

Becomes:

TweenLite.to(itemList[0], scrollSpeed, {x:itemList[0].startPoss -  itemList[0].width, scaleX:itemList[0].cScale, scaleY:itemList[0].cScale });

Also, those tweens you show are all local variables and should be disposed of when the tween terminates. At least in theory...