Flash CS3 / Flex 2 / AS3 Error #1176

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

4 thoughts on “Flash CS3 / Flex 2 / AS3 Error #1176

  1. public var s1:String
    public var b1:Array = (insert alphabet)
    s1 = txtInput.text
    s1 == b1
    li = b1.charAt(i)
    I’m trying to set the array as the input text, but it won’t let me- what should I do?

  2. Pingback: curtismorley.com » Updated ActionScript Error #1176

Comments are closed.