Hey databell
This is to do with what the others have all been telling you - the tween variable needs to be declared somewhere where it will remain in memory until it has finished. If it is declared inside a function, it only exists within the "scope" of that function.
so if I have
the variable name "zoomOutTween" only exists within the function zoomOut. Once the function is finished, the variable name no longer exists. This is when things get a bit complicated - it's to do with how Flash deletes things.PHP Code:function zoomOut(e:Event):void
{
var zoomOutTween:Tween=new Tween(myObject,"scaleX",Strong.easeInOut,endX,beginX,tweenDuration,true);
//other stuff
}
The thing is, the variable name no longer exists (if you tried to access zoomOutTween outside of the function, it would return an error). But the tween itself still exists in memory, and it will still work. Some of the time.
The thing is, Flash periodically does a sweep to find any objects being used in memory which no longer have any references to them. This includes event listeners, variable names and instances on the display list. Now the tween you created in the function still exists, but has no reference to it (the only reference you had, the variable name, stopped existing after the function ended).
The reason why the issue is happening randomly is that it depends on when Flash performs a sweep. There's no way of controlling this.
The solution is to have the variable name exist in a scope beyond the function so declare it somewhere else:
Does that make sense?PHP Code://somewhere outside of the function
var zoomOutTween:Tween;
function zoomOut(e:Event):void
{
zoomOutTween = new Tween(myObject,"scaleX",Strong.easeInOut,endX,beginX,tweenDuration,true);
//other stuff
}
