Calling a dynamic method in a timeout

Probably something more related with Haxe Language than OpenFL. I need to receive a function name and a time from a remote site and call that function after that time passed. First thing I did was this

timerCheck = new Timer(e.timeout * 1000);	
var cb = Reflect.field (this, e.action);		
timerCheck.addEventListener(TimerEvent.TIMER, cb);
    timerCheck.start();

But the call throws an exception when I tried to access any of the properties of the class. It works fine if I replace the code above for the following one

	var cb = Reflect.field(this, e.action);		
	Reflect.callMethod(this, cb, [null]);

Seems to be obvious why it worked in the second case. However I don’t figure out how to place a delay in the middle.

	var cb = Reflect.field(this, e.action);		
	haxe.Timer.delay(cb, e.timeout * 1000);

seems not to be working either. Any advice would be appreciated.

Best regards
Luis

If you want, using Actuate.timer might be convenient

Actuate.timer (e.timeout).onComplete (e.action);

Hello, thanks for the response but unfortunatelly I have the same result. It calls the method of the class, but it doesn’t have the reference to “this”…

Have to use a Walkaround. I created a class Trigger with 3 fields.
caller:Dynamic ( The instance of the class)
methd:String ( the method to be called)
params: Array: Params

and one method

public function trig(){
var cb = Reflect.field(caller, method);
Reflect.callMethod(caller, cb, [null]);
}


then in the main code I created a function

private var trigger:Trigger = new Trigger();

public function mytrigger(){
trigger.trig()
}

then in the code I want to make the delayed call

trigger.caller = this
trigger.method = e.action
haxe.Timer.delay(mytrigger, e.timeout * 1000);

Works fine… Not very “pure” but it worked…

Thanks anyway and hope this helps to someone else
Luis

You could also try:

Actuate.timer (e.timeout).onComplete (function () Reflect.callMethod (this, e.action));

You could do variations as well, but basically making a quick anonymous callback function to help encapsulate what you’re after