views:

31

answers:

1

I want to put shortest int in shortest:

shortest = 500;

for(i = 1; i <= _global.var_process_count; i++)
{
    if(_root["process" + i].process_time_original.text < shortest)
        shortest = _root["process" + i].process_time_original.text ;

}   

what's wrong with above lines of code?

+2  A: 
  • The code is not ActionScript-3, it is either AS-2 or lower.
  • You are not casting the string (textfield.text) to a Number.
  • What if the smallest number is 501 (or anything greater than 500)?

Try the following code:

var shortest:Number = Number.MAX_VALUE; 
for(i = 1; i <= _global.var_process_count; i++) 
{
  var t:Number = Number(_root["process" + i].process_time_original.text);
  if(isNaN(t)) //in case the text is not a valid number.
    continue;
  if(t < shortest) 
    shortest = t;
}
trace("shortest number is " + shortest);
Amarghosh
There is no _global in as3.
teehoo
@teehoo neither an `_root`; That's exactly why I said that the code is not AS3 and retagged the question accordingly.
Amarghosh
so what's is in as3 ?
ehmad11
yh, i apologize it was not as3 and this thing worked: var shortest:int; shortest = _global.var_process_time; var GoFor:int; for(i = 1; i <= _global.var_process_count; i++) { var t:Number; t = Number(_root["process" + i].process_time_original.text); if(isNaN(t)) //in case the text is not a valid number. continue; if(t < shortest GoFor = i; } } _root["process" + GoFor].playState = 1;
ehmad11