Flash CS3 / Flex 2 / AS3 Error #1176: Comparison between a value with static type String and a possibly unrelated type int.
Problem:
Flash won’t compile because it doesn’t like to compare an int with a String.
Fix:
Thank heavens for Strict Typing. Without it we wouldn’t get such nice errors. Just change the type from an “int” to a String and you will be on your way. If you need it to really be an int then you can cast the second variable to be an int rather than a String. See code example below
Bad Code:
var dropNum:int;function bob():void
{
var myText:String = “2”;
var curNum:String = “3”;
dropNum = myText.substr(0,1);
if (curNum == dropNum) {
someCode();
}
}
Good Code:
var dropNum:String;
function bob():void
{
var myText:String = “2”;
var curNum:String = “3”;
dropNum = myText.substr(0,1);
if (curNum == dropNum) {
someCode();
}
}
or
var dropNum:int;
function bob():void
{
var myText:String = “2”;
var curNum:int = 3;dropNum = Number(myText.substr(0,1));
if (curNum == dropNum) {
someCode();
}
Hope this helps solve ActionScript Error 1176 and Happy Flashing
Curtis J. Morley