No matter what I do I cannot solve a tween AS3 Garbage Collection problem I am having that is wreaking havoc on my tween instances working correctly/consistently. Some Sprites never tween at all, some do but only part way. And it effects different ones almost each time.
I have read a fair amount recently on AS3 Garbage Collection and improperly referenced Tweens and other asynchronous instances getting picked up in mid process. I am experiencing the signature inconsistent behaviour that the I have read of.
I have tried using class level Static and non static properties to store references to my Tween instances so they will not be marked for GC. No luck. I have placed references to them in Class level Arrays, I have also used TweenMax’s static to() Method that insures that it will shield it from GC and its alt. non Static constructor instantiation, with persist:true. I also implemented another custom package; GCSafeTween(), other users said it does as it should, but it’s not working in my case.
To test the GC problem, I edited the two eventListerners() in the Adobes’ fl.transitions.Tween so that their default weakReference property was false. Doing this made the Tween work correctly. But that’s a terrible solution.
Here’s my code. Its kinda stripped down just to show the setup.
Thanks for helping me solve this one!
package {
import DataModel;
import StackDisplay;
import flash.display.*;
import flash.events.*;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
public class Main extends MovieClip {
private var _dataModel:DataModel;
private var _stackDisplay:StackDisplay;
private var _visibleAsset:uint;
private var _timer:Timer;
private var _timerTweenOut:Tween;
private var _timerTweenIn:Tween;
public function Main () {
_dataModel = new DataModel();
_stackDisplay = new StackDisplay(_dataModel, this);
configureListeners ();
}
private function configureListeners ():void {
_stackDisplay.addEventListener (Event.COMPLETE, initTimer, false, 0, true);
}
private function initTimer (evt:Event) {
_timer = new Timer(1500);
_timer.addEventListener (TimerEvent.TIMER, timerNext, false, 0, true);
_timer.start ();
}
private function timerNext (evt:Event) {
_timerTweenOut = new Tween(_stackDisplay.assetArray[_visibleAsset], "alpha", Regular.easeOut, 1, 0, 7, false);
_visibleAsset++;
_timerTweenIn = new Tween(_stackDisplay.assetArray[_visibleAsset], "alpha", None.easeOut, 0, 1, 7, false);
}
}
}