## AMF Tutorial part 3 added

Hey! I finally took the time to write up the last part of my AMF tutorial.

Hope it answers your questions!

-Simon

Posts tagged ‘actionscript’

Hey! I finally took the time to write up the last part of my AMF tutorial.

Hope it answers your questions!

-Simon

I know, I was supposed to write to my blog more often than this, but I was pretty busy. Anyway, here it is! You can access it through the Tutorial link at the top of the page!

Enjoy!

PS: Feel free to leave any feedback.

I ran into a problem the other day where, I’m pretty sure a lot of you actually ran into as well, number formatting with AS3.

The big problem is that Math.round doesn’t allow you to specify a precision.

I tried to make this function work as closely as PHP’s number_format() function, here’s my attempt:

function numberFormat(num:Number, decimals:int = 0, thousands:String = ','):String { var buffer:String = ''; var truncate:Number = 0; var orig:String = ''; if (decimals > 0) { var ratio:int = Math.pow(10, decimals); var tempDecimal:Number = (Math.round(num * ratio) / ratio); truncate = (Math.round((tempDecimal - Math.floor(num)) * ratio) / ratio); if (truncate == 1) { num += 1; truncate = 0; } orig = Math.floor(num).toString(); } else { orig = Math.round(num).toString(); } var iteration:int = 0; for (var i = (orig.length - 1); i >= 0; i--) { if (((iteration % 3) == 0) && (iteration > 0)) { buffer = thousands + buffer; } buffer = orig.charAt(i) + buffer; iteration++; } if (truncate > 0) { buffer += '.' + truncate.toString().substr(2); } return buffer; }

Hopefully, it helps you resolve your number formatting issues.

Hello all, I just now added a new section to my blog, a tutorial section.

For now, there is only a partial one on AMF connectivity between ActionScript and PHP.