3 Replies Latest reply on Oct 9, 2008 3:43 AM by atta707

    I'm desperate for some help

      I need to call a method name from the database, and depending on the method name, the corresponding method will be called. Like duh...
      Can anyone give me a sample anything really that can help
        • 1. Re: I'm desperate for some help
          atta707 Level 2
          Assuming you've a class called TestClass and it has a method called sayHello, this should work:

          private function dynamicCall() : void {
          var tc:TestClass = new TestClass();
          // tc.sayHello();
          var method:String = 'sayHello';

          • 2. Re: I'm desperate for some help
            SamuelYeo Level 1
            Thank you but i have to ask.. whats in the method sayHello. what is the tc[method]()?
            • 3. Re: I'm desperate for some help
              atta707 Level 2
              You method would be in some class. Right? So TestClass is your class.

              Now this class may have many methods; sayHello is one such method. Of course, it is example only.

              the [] notation allows you to access dynamic properties, both member variables and functions, of a class. So assume that you've stored name of the method sayHello as a string in the database. You read it in a variable. Instanticate your class and use [] operator to access the function and add () to actually call this method.

              This is like saying tc.sayHello(); only in this case the name of the method is given as a string read from the database.