Link to home
Start Free TrialLog in
Avatar of walker6o9
walker6o9

asked on

Using Private Variables To Avoid Garbage Collections

Garbage collection is occasionally recycling my tween variables and thereby killing my tween.

I was wondering if it would be possible to use a private array of variables that I reset after the tweens are completed, since I believe garbage collection does not apply to private variables (please correct me if I am wrong so far).  However, i seem to be having trouble with the private variables.

here is my code on this.  really the slideBlade function is the only revelant part, but I thought I would also include the part where it is called, since it runs four times in a row.  (bladeTotal is always equal to 4)
public function slideBlade(which, pos, bladeTotal) {
			
			trace(bladeTotal+": bladeTotal");
			
			
			var tween:Tween = new Tween( which, "x", Regular.easeInOut, which.x, which[pos], .6, true);
			
		}
		//--------------------------------------------------------------------------------
		public function bladeEngine(which) {
			removeThumb(null);
 
			if (this.currentBlade == which) {
				for (x = 1; x <= bladeTotal; x++) {
					whichBlade = this["blade" + x];
					slideBlade(whichBlade,"closePos",bladeTotal);
				}
				which.blade.gotoAndStop(1);
 
				this.currentBlade = null;
				this.bladeNumber = 0;
			} else {
				if ( this.currentBlade != null) {
					this.currentBlade.blade.gotoAndStop(1);
				}
				if (which.bladeNum < this.bladeNumber) {
					for (x = which.bladeNum + 1; x <= bladeTotal; x++) {
						whichBlade = this["blade" + x];
						slideBlade(whichBlade,"closePos",bladeTotal);
					}
				} else {
					for (x = 1; x <= bladeTotal; x++) {
						if (x <= which.bladeNum) {
							whichBlade = this["blade" + x];
							slideBlade(whichBlade,"openPos",bladeTotal);
						}
					}
				}
				this.currentBlade = which;
				this.bladeNumber = this.currentBlade.bladeNum;
				this.currentBlade.blade.gotoAndStop(2);
 
				if (this.currentBlade == which) {
					buildTree( this.bladeNumber, this.currentBlade.bladeName, "", "" );
				}
			}
		}

Open in new window

Avatar of asaivan
asaivan
Flag of United States of America image

Yeah, just create a private var outside your function block, e.g.

private var tween:Tween;

then in your function:

tween = new Tween(...);

That should stop your tweens from being killed.

Is that not working for you?
Put them all in an array / object container. Pop/shift them as you complete them or just dump the container when they're all done.
Avatar of walker6o9
walker6o9

ASKER

MattKenefick-
I'm sorry, I'm not sure how that would work?  Do you kill them after they run?  Can you show me how that would work?
ASKER CERTIFIED SOLUTION
Avatar of MattKenefick
MattKenefick
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
BRILLIANT!