author: Krasimir Tsonev

Hi there, I'm . Senior front-end engineer with over 13 years of experience. I write, speak and occasionally code stuff. Follow me on Twitter, GitHub, Facebook or LinkedIn

Delegation in AS3

I just can't code without delegation. I'm using it every day and wanted to share this method with you.
Here is the class:
 package {
    public class Delegate {
      public static
      function create(handler: Function, ...args): Function {
        return function (...innerArgs): void {
          handler.apply(this, innerArgs.concat(args));
The usage:
import flash.utils.setTimeout;
    setTimeout(Delegate.create(func, "param1text", "param2text"), 1000);
    function func(param1: String, param2: String): void {
      trace("func param1=" + param1 + " param2=" + param2);
And the result of the code:
func param1=param1text param2=param2text
If you enjoy this post, share it on Twitter, Facebook or LinkedIn. Or maybe comment below: