The focus of this article is to know about power of your own events. Considering you are familiar with events, still we will see some brief introduction about events as it is basic of your own events.

]]>I thought it would be handy if I put it in an article so everyone can use it.

As you probably already know ActionScript2 doesn’t have it's own built in currency formatting function, so you have to provide your own.

This example is from one of the currency formatting functions I have used for several years.

It's relatively simple in what it does, but in my view simple is good.

First of all, for those of you that want to know how to call the function, here is an example.

newFormatedVariable = formatAsDollars(yourVariable);

Now for the function itself which is fairly straight forward .

Firstly we give the function a name.

function formatAsDollars(amount)

{

Then we test to see if it is a number.

if (isNaN(amount))

{

return ("0.00");

} // end if

Next we round it.

amount = Math.round(amount * 100) / 100;

var curr6 = String(amount);

and split it at the decimal point

var curr3 = curr6.split(".");

and place the results in an array.

if (curr3[1] == undefined)

{

curr3[1] = "00";

} // end if

if (curr3[1].length == 1)

{

curr3[1] = curr3[1] + "0";

} // end if

After testing the values in each part of the array for length, we can then append the necessary zero if it needs it.

var curr4 = new Array();

var curr2;

We loop through the array

for (var curr1 = curr3[0].length; curr1 > 0; curr1 = curr2)

{

We round up

curr2 = Math.max(curr1 - 3, 0);

curr4.unshift(curr3[0].slice(curr2, curr1));

} // end of for

Now we rejoin the dollars and the cents

curr3[0] = curr4.join("");

return ("" + curr3.join("."));

} // End of the function

And out put the result.

_root.onEnterFrame = function ()

{

text_two.text = formatAsDollars(text_one.text);

};

If you need more information on flash and Actionscript2 you will find some free tutorials on Asctionscript 2, and a lot of other content on building applications with Flash and ActionScript at: www.interactivewebconcepts.net

]]>