When does 75 equal 61?
- Tuesday, August 31st, 2010 -
When it has a leading zero in actionscript 2 of course.
trace(Number("075"));
// ActionScript 3.0 75
// ActionScript 2.0 61
try it for yourself!
and then add this code somewhere to strip off those zeros
var movieLenStr:String = '0075';
trace(movieLenStr + ' does NOT equal ' + Number(movieLenStr));
while(movieLenStr.charAt(0) == '0') {
movieLenStr = movieLenStr.substr(1);
}
trace(movieLenStr + ' does equal ' + Number(movieLenStr));
So just to finish the thought – the problem is that in AS2 it’s interpreting that leading zero as an octal number and therefore converts it differently. In AS3 it just ignores the zero. It’s all spelled out in the livedocs:
In ActionScript 3.0, the
Number()function no longer supports octal, or base 8, numbers. If you supply a string with a leading zero to the ActionScript 2.0Number()function, the number is interpreted as an octal number, and converted to its decimal equivalent. This is not true with theNumber()function in ActionScript 3.0, which instead ignores the leading zero. For example, the following code generates different output when compiled using different versions of ActionScript
from this entry: http://www.adobe.com/livedocs/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000048.html
