8 Replies Latest reply on Apr 17, 2011 7:33 PM by NeoRamza2

    How to pass a Class as a parameter of a method?

    NeoRamza2 Level 1

      I have a method like below. Inside this method I need to create a variable that his type is the type of the class I have passed as a method's parameter.

       

      For example, if I call the method like this "Meth1(ClassPerson);" insed the method I need to declare a  variable of class "ClassPerson", but if I call like "Meth1(ClassCity);" I need the same variable to be declared as a ClassCity.

       

      public function Meth1( /*I dont know what to put here*/   ):void{

           /*I dont know what to put here to declare my variable*/

       

           /*here

           comes

           more

           code

           using

           the

           variable*/

       

      }

       

       

      I tried as below but dont worked:

       

      public function Meth1( classtype:Class):void{

           var var1:classtype = new classtype();

       

           /*

           ...

           */

      }

      Can someone help me?