How to format a number as money

Recently I was working on a project where I had to take a number that represented a monetary value and display it as money. For example say I had a numeric variable that contained the value of 10000 and I needed it to display like money with the commas and dollar sign like this $10,000. So in other words I needed the string representation. That is what this simple function that I am posting does. I have written it here in Flash ActionScript 3 as a static function of a class, but you could adapt it however you need to. Here is the code:

public class Formatter
{
    public static function formatMoney(val:int):String
    {
        var isNegative:Boolean = false;
        var moneyVal:String = val.toString();
        var len:uint;
        if(val < 0)
        {
             isNegative = true;
             moneyVal = moneyVal.replace(/-/, "");
        }
        len = moneyVal.length;
        for(var i:int=len; i>0; i-=3)
        {
            if(i == len)
            {
                continue;
            }
            var firstHalf:String = moneyVal.substring(0, i);
            var lastHalf:String = moneyVal.substring(i);
            moneyVal = firstHalf+","+lastHalf;
        }
        if(isNegative)
        {
            return"$-"+moneyVal;
        }
        return "$"+moneyVal;
    }
}

Latest Project – Rotating Flash Banner

I just recently did a freelance project for makeityourweb.com It is a rotating banner. It is populated by XML. The XML file lets you control what images are loaded along with the time each image is up and also whether or not it has the navigation in the lower left corner. It’s pretty cool! Go check it out at http://www.kttape.com/

The Proper Way of Referencing Elements on a Web Page

I was recently working on a web page that was not displaying some Flash elements properly on some people’s browsers or so I thought. After beating my head for a bit I realized what the problem was. The .swf file that I was referencing had an absolute path that included the “www.” in the URL. Here is an example: “<param name=”movie” value=”http://www.mywebsite.com/swfs/my_movie.swf” />. The problem was when someone went to the site and did not include the “www” for example: “http://mywebsite.com”. The solution to this is rather simple and should be the practice you use when referencing elements on your pages. It’s called root referencing and here is an example: “<param name=”movie” value=”/swfs/my_movie.swf” />. You leave off the “http://”, the “www” and the site name and instead just put a “/” at the beginning. This will work in all cases even if the page that is referencing the element is nested multiple folders deep.

Fun Games For Your Next Party

I recently played some fun games that I wanted to pass on. I played them at Christmas parties, but they would work great for any holiday or party.

The first one is a taste testing game. Here’s how it works. You need a variety of sodas that are similar in color and taste. The game I played used 7 two liter bottles. What you do is pour each one into its own cup and write a number on it. Then you take and pour a little from each cup into each players cup one flavor at a time allowing them time to drink it and mark down on a piece of paper what flavor they think that it is. Here is the break down for the game I played:

1. Sierra Mist
2. Squirt
3. 7up
4. Generic Brand Squirt
5. Generic Brand 7Up
6. Fresca
7. Sprite

The next game is a point game that involves eating M&Ms. Here is how it works. First you count out a certain amount of each colored M&M and place them in a brown paper sack. There is a sack for each player. Then each player pulls an M&M out of the sack without looking and shows it to the person keeping score. You keep doing this until the first person reaches the desired amount of points. The game I played the winning number was 500 and here is the count of each color along with its corresponding points:

Blue – 5 pts (8 M&Ms)
Green – 10pts(7 M&Ms)
Orange – 25pts (6 M&Ms)
Red – 50pts (5 M&Ms)
Yellow – 75pts (4 M&Ms)
Brown – 100pts (3 M&Ms)

The last game is one that I made for a Christmas party that we had, It’s Christmas Bingo. You can check it out and print off some of your own cards for your next Christmas party by going here: http://www.joebillman.com/christmas-bingo.php. Enjoy these game ideas!

Error #2044: Unhandled IOErrorEvent:. text=Error #2032: Stream Error.

If you have ever received this error it can be quite frustrating and there are a lot of not so helpful answers out there on the web. Because of that I wanted to post this real simple solution. All you need to do is add an event listener to the item calling the URLRequest. Here is a simple example using a Sound object:

var audio:Sound = new Sound();
audio.addEventListener(IOErrorEvent.IO_ERROR, handleIOError);
audio.load(new URLRequest("myfile"));

function handleIOError(evt:IOErrorEvent):void
{
//handle error if needed
}

It’s that simple. I hope this helped! If this helped please post a comment so that others can find this simple solution.

Adobe Creative Suite Tools Not Showing Up Right

This is one that I found a while back, and just recently was reminded of it again. The other day I saw a forum post stating that Flash won’t display the path I’m drawing with the pencil tool. I had something similar to this happen with the eraser tool in Fireworks. It too wouldn’t display right and was flickering. The system I was using was running was Windows Vista and I had the Appearance set to Aero and that was what was causing the issue. Just by setting it to the Basic mode (Without the transparency) that fixed it. This also is the case for Windows 7. This is kind of a random issue and appears to affect multiple Creative Suite programs. So far I have heard of it affecting Flash, Fireworks and Illustrator. I was getting the issue with CS3 and when I upgraded to CS4 it no longer happened in Fireworks at least. I also have Windows 7 and CS4 and have noticed that it still is an issue in Flash with the pencil tool. The line you draw with the tool doesn’t show up until you let up on the mouse button. If you happen to run across this weird issue and want to find a solution try changing the Appearance Settings.

if(computerWorking){iBeHappy = true;}

I am writing this from my computer again instead of my laptop. Woo hoo! It is great to have it working again and even better working with Windows 7. Man I don’t know how I ever got by without a 64bit version of Windows. Windows 7 64bit ROCKS! I am loving it. I had to just write briefly and say how much I love that fact that my machine is working again and that I will soon be posting the Reflection class that I blogged about previously. Also I want to give a quick shout-out. I work with two of the best programmers and all-around good guys in the whole world, Dan and Josh. They just recently got new blogs up so I wanted to put up some links to them. If you like Flash and or code go check them out. Dan’s blog Josh’s blog

Computer Problems

So just when I thought that I was doing good on keeping up with my blog my computer crashed. The mobo on my computer bit the bucket and I am waiting for a replacement. I am writing this entry from my 7 year old piece of junk laptop. I have been watching some more sessions from MAX and am excited to try the beta of Flash CS5. Also at work I recently wrote a cool class that dynamically adds a reflection to a Display Object in Flash and will be putting that up soon when my computer is up and running again. My current boss Dave Clark is real cool and wants me to put it up to give back to the Flash community. Also we are going to be putting up some cool free stuff to help people learn Spanish free online so if you are looking to learn Spanish click on this link and check it out.

Adobe MAX 2009

So this last week was MAX and the bummer news for me is that I didn’t get to go this year. On a good note though they put up a bunch of cool stuff online. If you didn’t get to go either or are new to what MAX is go check it out at http://max.adobe.com/online/ Monday’s keynote was awesome! They announced some way cool things for the next release of Flash. The biggest announcement was that Flash CS5 will enable developers to develop Apple Apps in Flash and then compile them down as native apps that can run on the iPhone and iPod touch. Pretty dang sweet! Another cool thing they announced is that finally the code editor in Flash will have custom class introspection and Flash Builder (new name for Flex Builder) has a new Flash project. This allows you to edit a document class in Flash Builder and then compile and run from Flash Builder. To see more on these features watch the free session from Monday, October 5, 2009 entitled Secret Session: Flash Professional. MAX is awesome and I am looking forward to going next year. They also announced that later this month they will be putting up all of the sessions so that we that couldn’t go can check them out. One last cool announcement was that they will be doing a public beta for Flash CS5. To go sign up to be notified for that go to http://labs.adobe.com/ All and all some pretty cool stuff.