开发者

How Can I Detect A Data Type in AS3

开发者 https://www.devze.com 2022-12-25 13:27 出处:网络
I\'d like to make a call to a function and send either a string or an integer... function getImage(val:*):void{

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){
        s开发者_JAVA百科witch(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


Use the is keyword:

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


You can also use the method typeof()

for example:

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

This will trace out string

0

精彩评论

暂无评论...
验证码 换一张
取 消