Eine Lightweight-Tweenklasse ist sicherlich eine feine Sache. Aber das hier sieht mir nach einer einwandfreien Lösung aus, die auch mit den nativen Tweens läuft. Rund 70 Tweens laufen bei mir gleichzeitig ab, und keiner wird mehr vorzeitig abgebrochen bzw. garbage collected. Die Lösung ist ein Dictionary, und so sieht sie aus:
Zitat:
PROBLEM
Tweens finish early because they get randomly garbage collected
SOLUTION
Some form of reference that prevents garbage collection BUT does allow garbage collection when appropriate.
(Note the last part you don't want your Flash to clog up memory after executing for a long period of time)
Some people state declaring each tween globally (sometimes doesn't work?) others have made each tween a property of some global object. This is my solution for handling many tweens...
MY SOLUTION
//Anti Garbage Collection for Tweens
var antiGC: Dictionary = new Dictionary(false);
//Function with two tweens
function zoomIn(){
var scale:Number = diagram_mc.scaleX *1.12;
var xT:Tween = new Tween(diagram_mc, "scaleX",Strong.easeOut, diagram_mc.scaleX, scale, 5);
xT.addEventListener(TweenEvent.MOTION_FINISH, tweenFinished);
antiGC[xT] = xT;
var yT:Tween = new Tween(diagram_mc, "scaleY",Strong.easeOut, diagram_mc.scaleY, scale, 5);
yT.addEventListener(TweenEvent.MOTION_FINISH, tweenFinished);
antiGC[yT] = yT;
}
//Allows Garbage Collection
function tweenFinished(e:TweenEvent){
antiGC[e.currentTarget] = null; //GC Object
delete antiGC[e.currentTarget]; //GC Key
}
EXPLANATION
-Global dictionary with strong references will not be garbage collected
-Local tweens ok (e.g. in functions)
-...because tweens are stored in the dictionary
-EventListener triggers a global function to remove all references once finished
-...removing references allows garbage collection to do what it does
Note if you want your own MOTION_FINISH listener just remember to call the tweenFinished function
|
Danke dem
unbekannten Spender! Herzlich, twb