If we don't use the second function (getClassName), the output would be '[object MyClass]' so that's why we slice a string to get only the very class name. Now you can call Debug.write instead of trace in the debug function on every class:

Friday, November 05, 2010

While the Adobe flash.globalization package is still in beta, which includes a CurrencyFormatter class, we need to find a quick way to display an amount formatted as currency, with thousand separator and decimal mark.In this case, we are targeting USA and UK so the thousand separator is a comma and the decimal mark is a point.Right, so this is some simple logic used:

multiply the number by 100 to get the decimals

check if new number is zero or less than 100 (if less than 100 then is a decimal)

otherwise get the decimals and keep them aside

divide the rest of the number into groups of three and push them into an array

reverse the array and add the decimals

voila! you got the number formatted as currency!

So, yeah, the commas in that separate elements in the array work now as thousand separators :)And here is the code:

Thursday, November 04, 2010

As a programmer, sometimes you find yourself dealing with this nasty badly written code and your task is to fix some even nastier and ugly looking bugs.

Whether is code you wrote yourself some years ago or someone else's (which makes it even worse) as it's your task to dig into the code, you will need help, help to understand where in heaven one of the dozens of public methods in that class is being called.

Yeah, in that code, almost all the methods in all the classes (including the main one) are public and of course is highly coupled making it almost impossible to read or to maintain.

Spaghetti code, hundreds of messy lines of 'code' (?) in each messy class... oh the joy...After hours of work, after cursing everyone around you, you find the function which is causing the issue but... where is it being called? who's calling it? why?Here it comes Stack Trace to the rescue! woohoo!And the line of actionscript 3 that has saved me from cursing even the ones that are not around me is:

trace(new Error().getStackTrace());

That line will output in the flashlog the path (including class names, and code lines) that the thread takes before throwing the error (you will need flash player debugger to see the error). Now we now where the function is being called, time to continue debugging...