Creating Anonymous Functions : function variable « Function « Flash / Flex / ActionScript






Creating Anonymous Functions

 

//Here is the syntax for an anonymous function:
/*
function():datatype {
  statements
};
*/

package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){

        var fSayHi:Function = function(sName:String):void {
          trace("Hi, " + sName);
        };
        fSayHi("Joey"); 

    }
  }
}

        








Related examples in the same category

1.Function type variable
2.Referencing Functions
3.Bound Methods, which is treated as a value
4.A method assigned to a variable can be invoked via that variable using the standard parentheses operator, ( ).