There was another question, how to add a function to an array, or why is the function in the array empty?

Wrote function:

private function subscribeToCallback(name:String, func:Object) : void { callbacks[name] = {'callback': func}; } 

Next, in the class constructor, I call a function with parameters:

  subscribeToCallback("sConn", function():void { trace("sConn"); }); 

And actually further in 2-5 seconds I try to get the data from the array, which I declared after creating the class:

  public var callbacks:Array = new Array(); 

I try to get this way:

  trace(callbacks["sConn"].callback); 

And in response, I get in the console:

  function Function() {} 

Why is it empty? How can I thrust a function into an array?

    1 answer 1

    Hey. Here you are trying to bring an object of type Function to the line that comes out.

     trace(callbacks["sConn"].callback); 

    To call a method that is represented by this object, use the call () function.

     trace(callbacks["sConn"].callback.call(null))