4

I'd like to make a call to a function and send either a string or an integer...

function getImage(val:*):void{
    if(val == String){
        switch(val){

            case'next':
            loadNext();
            break;

            case'prev':
            loadPrev();
            break
        }
    }else{
        loadImg(val);
    }
}

and vary my function accordingly... anyone know how to detect the parameter type?

Thanks -J

Howard Zoopaloopa
  • 3,798
  • 14
  • 48
  • 87

2 Answers2

6

Use the is keyword:

if(val is String) {
  //do something
}
bedwyr
  • 5,774
  • 4
  • 31
  • 49
1

You can also use the method typeof()

for example:

var myTest:String = 'This is a string';
trace(typeof(myTest));

This will trace out string

Tempname
  • 565
  • 5
  • 26