[as2] advice on tween class

hello

i’ve been struggling with the tween class for a couple hours and have gotten it working via a couple different approaches. i was wondering which seems like the most efficient way, and if anyone has any suggestions to clean it up.

i need to be able to control about 12 buttons fading in and out, i just used 4 in the test. the simple “for” attempt (pink) fell flat. attaching the function directly to an instance (grey), each specified individually (turquoise) and the array (green) all worked fine. pink, turquoise and green use anonymous functions. i think the array is the way to go, but please let me know if you see anything that could be improved. i have a feeling that using a “for” statement to generate the array might be worth looking into, but i haven’t tried it yet.

the above is confusing, so please look at the code, it’s much clearer.

i am attaching the test file, but everything is copied into this post, so it’s probably redundant.

thank you

craig

import mx.transitions.Tween;
import mx.transitions.ease.*;

// pink squares

for (i=1; i<=4; i++) {
	//
	eval(ps+*).onRollOver = function() {
		fadeOut(this);
	};
	//
	eval(ps+*).onRollOut = function() {
		fadeOut(this);
	};
}


// center square

ls.onRollOver = function() {
	var twOut = new Tween(this, "_alpha", Strong.easeOut, this._alpha, 0, 1, true);
};
//
ls.onRollOut = function() {
	var twIn = new Tween(this, "_alpha", Strong.easeOut, this._alpha, 100, 1, true);
};


// turquoise squares

ts1.onRollOver = function() {
	fadeOut(this);
};
ts1.onRollOut = function() {
	fadeIn(this);
};
//
ts2.onRollOver = function() {
	fadeOut(this);
};
ts2.onRollOut = function() {
	fadeIn(this);
};
//
ts3.onRollOver = function() {
	fadeOut(this);
};
ts3.onRollOut = function() {
	fadeIn(this);
};
//
ts4.onRollOver = function() {
	fadeOut(this);
};

ts4.onRollOut = function() {
	fadeIn(this);
};

// green squares

var greens_array:Array = new Array(gs1, gs2, gs3, gs4);

for (i=0; i<greens_array.length; i++) {
	greens_array*.onRollOver = function() {
		fadeOut(this);
	};
	greens_array*.onRollOut = function() {
		fadeIn(this);
	};

}

// anonymous functions

function fadeIn(which) {
	var twIn = new Tween(which, "_alpha", Strong.easeOut, which._alpha, 100, 1, true);
}
//
function fadeOut(which) {
	var twOut = new Tween(which, "_alpha", Strong.easeOut, which._alpha, 0, 1, true);
}



stop();

on the face of it your code looks OK

nice to see some trace statements in there:stare:

you’ve used the same variable names twice

you have fadeOut() twice on rollover and out in one instance

I think you should stick to the function you got set up

shrugs