George Reith
George Reith

Reputation: 13476

AS2: For loop found number but string is required

Here is the snippet of my code which is causing this error:

    for (a=0; a<cabinets[index].length; a++) {
        if (cabinets[index][a].xPos>cabinetMap.xPos) {
            var newX:Number = cabinets[index][a].xPos-symbolParams.X_SPACING;
            enableSwitch(cabinets[index][a].mc,false);
            TweenMax.to(cabinets[index][a].mc,0.4,{_x:newX, ease:Expo.easeOut, onComplete:enableSwitch, onCompleteParams:[this, true]});
        }
    }

Which produces the following error:

Description: Type mismatch in assignment statement: found Number where String is required.

Source: for (a=0; a<cabinets[index].length; a++) {

Which is peculiar because when I alter it to: for (a="0"; a<cabinets[index].length; a++) { it throws no errors anymore however this is now incorrect because a is now a string.

Any ideas as to why this could be?

Upvotes: 0

Views: 1131

Answers (1)

Allan
Allan

Reputation: 3314

I am assuming you have declared a variable called a someone before that block of code and that it has either been explicitly or implicitly set to a String type.

Upvotes: 1

Related Questions