Calling a function name passed as a parameter?

I have created a function that applies a set of tweens to a movieclip. This function has a number of parameters, one of which I need to be the name of a function that is called when the tween is finished. The tweening itself works just fine. It is getting it to call a function specified as a string or other means passed as a parameter that is not working.

Here is an abbreviated example of the code:

[FONT=Courier New]//Inside the movieclip [/FONT]
[FONT=Courier New]doSpecialTween(this, 100, “callWhenDone()”);[/FONT]

[FONT=Courier New]//In root[/FONT]
[FONT=Courier New]_global.doSpecialTween = function(objectName, amount, endingFunction) {[/FONT]
[FONT=Courier New]//The tween itself is working just fine[/FONT]
[FONT=Courier New]myTween = new mx.transitions.Tween(objectName, “_alpha”, mx.transitions.easing.None, 0, amount, 1, true);[/FONT]

[FONT=Courier New]//It is getting the function name passed as a parameter to execute[/FONT]
[FONT=Courier New]myTween.onMotionFinished = function() { eval(endingFunction) }[/FONT]

[FONT=Courier New]}[/FONT]

[FONT=Courier New]function callWhenDone() {[/FONT]
[FONT=Courier New]trace(“tween finished!”);[/FONT]
[FONT=Courier New]}[/FONT]
[FONT=Courier New][/FONT]
Any ideas???


// old line:
doSpecialTween(this, 100, "callWhenDone()");
// new line (might need the quotes, not sure):
doSpecialTween(this, 100, callWhenDone);
//
//
//old line:
_global.doSpecialTween = function(objectName, amount, endingFunction) {
// new line:
_global.doSpecialTween = function (objectName:MovieClip, amount:Number, endingFunction:Function) {

Should get you on the right path, at least.

Hmm, I added the data types but still am not able to get it to work. Any other thoughts?

I am also trying _rootendingFunction with no luck.

when using callback functions in this manner, I sometimes pass another arg - the object where that function lives to avoid scope issues. So, syntax would be like so:

[AS]

this.myFunc = function(_func:String, _loc:Object, _arg:String) {
_loc_func;
}

this.callBack = function(_argsent:String) {
trace(_argsent);
}

myFunc(“callBack”, this, “this worked”);

[/AS]

I’d do it like this:

//Inside the movieclip 
doSpecialTween(this, 100).onMotionFinished = function()  {
	trace("tween finished!");
};
//In root
_global.doSpecialTween = function(objectName, amount) {
	return new mx.transitions.Tween(objectName, "_alpha", mx.transitions.easing.None, 0, amount, 1, true);
};