Home > Tween > Tween Class

Tween Class

Today while working on AS3 project which uses Tween, encountered a weired issue which causes the Tween to Freeze. This could be a pretty old issue, anyways here were the issue that i encountered and also possible ways of resolving that.

The code that causing the issue was due to the Tween was stored in a local variable and the variable might be garbage collected before the completion of the scripted motion.

Tween Code which may cause Freeze (Buggy)

function someFunction()
{
var myTween:Tween= new Tween(myObject, “x”, Elastic.easeOut, 0, 300, 3, true);
myTween.addEventListener(TweenEvent.MOTION_FINISH, listenerFunction);
// …
}

To prevent the tween code that causes Freeze , Here were few steps that we can do

1. Storing the tween variable globally.

Even if there is an event listener registered for an object, the object may be garbage collected if it’s a local variable ( with the scope of a function). To prevent this, declare the variable globally as in the following.

var myTween:Tween;

function someFunction()
{
myTween = new Tween(myObject, “x”, Elastic.easeOut, 0, 300, 3, true);
myTween.addEventListener(TweenEvent.MOTION_FINISH, listenerFunction);
// …
}

(Took this from Flash documentation, it is weird the way Flash Performs Garbage collection L or I am missing something here?)

2.Using Tween to Keep Reference in the memory until the tween motion is completed, This can be achieved by using Dictionary class or using a custom class to manage the way tween is garbage collected.

Reference links

# Documentation

# Adobe bug base

Advertisements
Categories: Tween
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: