Zane Clark Zane Clark - 6 months ago 39
ActionScript Question

Any way to Call A Function As A String?

I've just started a project, and am wondering if you can call a function (in an event listener) through a string.

import flash.utils.Timer;

var threesec:Timer=new Timer(3000, 1);
var whaton:String="tsecc"
threesec.addEventListener(TimerEvent.TIMER_COMPLETE, whaton);
function tsecc(tsecc:TimerEvent):void{

This does not work because of this line:

threesec.addEventListener(TimerEvent.TIMER_COMPLETE, whaton);

and this error code:

1067: Implicit coercion of a value of type String to an unrelated type Function.

I know what I am doing is horribly wrong, but is there a correct way to call a function in string format?

Do I have to add a property to the variable, do I have to create another type of variable?

threesec.addEventListener(TimerEvent.TIMER_COMPLETE, this[whaton]);  

I used "bracket syntax" to do this. You can learn more about it by searching on the Internet.