The 'problem' lies with ActionScript 2's static type checking. You can't directly modify a class because it checks that the property you're trying to access exists. However, you can do it if you bypass the type checking:
var Math2 = Math; // thing now holds a reference to the same Math class, but with no type set
// Add a new method
Math2.sinD = function(angle) {
return Math.sin(angle*(Math.PI/180));
};
// Now the Math has 'sinD' as a method
Or alternatively... (these both do the same thing)
Math['sinD'] = function(angle) {
return Math.sin(angle*(Math.PI/180));
};
However, this doesn't really help, because the static type checking is enforced at the calling places as well, so you can access any dynamically added methods.
Math.sinD(30) // This will not compile
Instead, you need to do:
var Math2 = Math;
Math2.sinD(30) // returns 0.5
Math['sinD'](30); // also returns 0.5
At which point, you may as well just create your own class rather than modifying the existing class.
Fortunately, for my case this means that there aren't any usages of these extensions (at least not statically typed usages), so I should be able to safely delete the extensions and not worry about it :)