PDA

View Full Version : For statement returns error when it is decreasing



superpeppe
August 13th, 2007, 10:19 AM
Hi

Usually when you use the for statement you want the starting value to be 0, and the ending value to be larger than 0. But I need it to count down, so let's say we have the following code:


package {
import Array;
import flash.display.Sprite;

public class test extends Sprite {
private var ARRAY:Array = [123, 456, 789]
public function test ():void {
for (var i:uint = ARRAY.length-1; i >= 0; i--) {
ARRAY[i]*=.5;
}
}
}
}
It returns an error:TypeError: Error #1010: A term is undefined and has no properties.
How should I then get it to count down?

Thanks in advance!

senocular
August 13th, 2007, 10:29 AM
a) import Array; <- incorrect. Array is top-level. The import statement is only used with classes in packages

b) you shouldn't use uint when counding down since i will always be positive. It would be possible to get caught in an infinite loop. Instead use int (uint is also slower than int)

c) The code you provided would not cause your error