Howard Zoopaloopa
Howard Zoopaloopa

Reputation: 3822

How Can I Detect A Data Type in AS3

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

Upvotes: 4

Views: 2186

Answers (2)

Tempname
Tempname

Reputation: 565

You can also use the method typeof()

for example:

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

This will trace out string

Upvotes: 1

bedwyr
bedwyr

Reputation: 5874

Use the is keyword:

if(val is String) {
  //do something
}

Upvotes: 6

Related Questions