I heard that AS boxes and un-boxes values every time arguments are passed into/out of functions.
A. Therefore, would this be faster?
var val = doWork(50,'hello', 2048); function doWork (param1,param2,param3){ t.text = param2; return param1+param3; }
B. Or this?
var val:Number = doWork(50,'hello', 2048); function doWork (param1:Number,param2:String,param3:Number):Number{ t.text = param2; return param1+param3; }
There’s no difference at runtime. AS 2 is run by the Actionscript Virtual Machine 1 (AVM1), which doesn’t support static typing, so type information is rather a hint for the compiler to help you catch type inconsistencies earlier. But the same code with or without type annotations produces the same bytecode.
AS 3 is run by AVM2, which supports both dynamic and static typing, so declaring types in the code eliminates some runtime lookup, which makes it faster to execute.