How to determine data type in AS3

I want to make a function call 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 changes my function accordingly ... does anyone know how to determine the type of parameter?

Thanks -J

+4
source share
2 answers

Use the is keyword:

 if(val is String) { //do something } 
+6
source

You can also use typeof () method

eg:

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

A line will open

+1
source

Source: https://habr.com/ru/post/1305720/


All Articles