Referencing Functions : function variable « Function « Flash / Flex / ActionScript






Referencing Functions

 

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


        var fArea:Function = calculateArea;
        trace(fArea(6, 6));
    }

    function calculateArea(a:Number, b:Number):Number {
      var nArea:Number = a * b;
      return nArea;
    }
  }
}
// 36

        








Related examples in the same category

1.Function type variable
2.Creating Anonymous 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, ( ).