ActionScript casting a string
If you do a string comparision that fails when by all indications that it should pass, you should do the following
var String tmpvar = someFunction();
if(tmpvar == "equivalentvalue"){
trace("true");
} else {
trace("false");
}
OUTPUT is:false
Instead Cast the return value to a String
var String tmpvar = new String(someFunction());
if(tmpvar == "equivalentvalue"){
trace("true");
} else {
trace("false");
}
OUTPUT is:true
var myArray:Array = new Array();
var someString:String = "asdf";
myArray[0] = someString;
.
.
.
var testVar:Object = myArray[0];
if (testVar instanceof String || typeof(testVar) == "string")
{
var typedVar:String = String(testVar);
// do something with typedVar
}
var String tmpvar = someFunction();
if(tmpvar == "equivalentvalue"){
trace("true");
} else {
trace("false");
}
OUTPUT is:false
Instead Cast the return value to a String
var String tmpvar = new String(someFunction());
if(tmpvar == "equivalentvalue"){
trace("true");
} else {
trace("false");
}
OUTPUT is:true
var myArray:Array = new Array();
var someString:String = "asdf";
myArray[0] = someString;
.
.
.
var testVar:Object = myArray[0];
if (testVar instanceof String || typeof(testVar) == "string")
{
var typedVar:String = String(testVar);
// do something with typedVar
}
Comments