views:

79

answers:

3

I have a function that takes as parameters 2 instances of a (custom) class. But they can each be one of several classes, and I need to then call another function based on what type they are. I'd like to do something like this:

function any_any(inst1, inst2) {
    this[inst1.classname + "_" + inst2.classname] (inst1, inst2);
}
function Circle_Line(circle:Circle, line:Line) {
    //treat this case
}

Should I go and define 'classname' in each of my classes, or is there a better way to get the class name of an instance? I don't know how to get typeof() to return anything other than 'object' for a custom class, maybe it's possible?

EDIT: It would be inconvenient to use the instanceof operator, as each class can be 1 of 6 (currently).

+1  A: 

You can use instanceof, or the 'is' operator, or the getQualifiedClassName method

Gabriel McAdams
A: 

You can youse instanceof

   var a:Number;

   if (a instanceof Number)
   {
    trace("a is a number");
   }
slayerIQ
A: 

another way to get the class of an instance is using

var c:Class = instance["constructor"];

then you can do something like this:

switch(c)
{
    case Circle:
        whatever();
}
frankhermes