7 Replies Latest reply on Nov 16, 2009 4:37 PM by Bayani Portier

    Dynamically catch a function call from an object at runtime

    Bayani Portier Level 1

      Hi,

       

      I have a bit of an interesting question.

       

      Say I have a dynamic object named Foo. It may have a set of explicitly defined functions:

       

      public function helloWorld():String

      {

           return "hello world";

      }

       

      public function get name():String

      {

           return "My Name";

      }

       

      etc.

       

      I want to be able to create a further function

       

      public function handleFunctionCall(functionCall:String, args:Array):*

      {

           trace("Function: " + functionCall + " was called with the arguments:");

           for(var i:int=0; i<args.length; i++)

           {

                trace(args[i]);

           }

      }

       

      The purpose of this is so that I can declare the object Foo and then call any function and handle it accordingly at runtime.

       

      e.g.

       

      var foo:Foo=new Foo();

       

      foo.bar();

      foo.whathaveyou();

      foo.whatever();

       

      Hope someone can point me in the right direction.