Taking my cars for a spin with Actionscript 3.0
August 12th, 2007 . by polyGeekThese cars were design in the Forza2 racing game for the XBox360. First off let me give credit where credit is due. I did not do the designs on the polyGeek car or the Seahawks car. That was done by Lee Nicholls the Global Solutions Director for Getronics, World domination hobbyist, woo-er of beautiful women, driver of outrageously fast cars, and Forza2 designer extraordinar.
You can view the source code here. ( The download zip is a little over a meg because I left in the images of the Adobe Fararri for you to play with.) I’ve commented the code pretty thoroughly so I don’t think there’s much point in going into details. I’ll just give a quick overview of how this works.
First off, there are XML files that describe a series of images. The code goes through and loads each image and places them one on top of the other.
As soon as all the images are loaded it runs through the series of images to display them each in turn giving the illusion of the car, or whatever you have photos of, rotating. That’s serves the purpose of letting the user know that they can rotate through the images. Just displaying a mouse-hand probably isn’t enough of an indication.
The mouse wheel also works to scroll through the images.
The images are loaded one after the other instead of all the requests going out at once. I found that there were some odd errors with making a request for 40 images all in one shot. Sometimes they would load and sometimes they wouldn’t. Loading in sequence solved all that.
As your drag your mouse across the image space it uses the width of the image and the number of images in the stack to calculate how much you need to drag your mouse before the next image displays. That way if you start from one side of the image space and drag all the way across it will rotate through all of the images. No matter how many there are.
Modulo to the resuce
There are few occasions to use modulo in Actionscript. That’s the mathematical operation using the “%” sign. Modulo gives you just the remainder after division. Example: 34 % 10 = 4 because 10 goes into 34 three times with 4 left over.
Modulo was very handy for solving an otherwise messy problem. References to each image are stored in an array. As you drag your mouse across the image space the code figures out which image needs to be visible at that point.
So what happens if the user is dragging through the last few images in the array and then needs to start back at the beginning of the array? You can imagine lots of messy if() statements to handle all that or, I can just take the modulo of the image I think they need to see with the length of the array and they will always see the correct image.
Example: suppose there are 30 images in the array ( 0-29). The user is dragging across the image space and displaying the last few images, 27, 28, 29, 30 . . . But there is no image 30. But if when I go to display an image I use the calculated image number modulo 30 ( length of the array ) then I’ll always be in the range of the image array.
So when I try to display image 30 I’ll get 0, and for 31 I’ll get 1 and so forth. Problem solved and no messing if() statements.












This is really cool. And I like your car! I have a 1.8T Jetta Wagon. Yes, I am a family man, but I can go fast!
wow! SWEET! this is some good stuff thanks for sharing!
Looks nice, will you make a runtime 3D aswell ?:)
@Randy, Jetta that goes fast? They make those?
In the real world I have a ‘95 Pathfinder that goes 0-100 in never. But let me tell you it’s nice to have around here when we get ice storms.
@admin, I’ll leave it to the Forza2 developers to do the 3D stuff. Unless drop shadows count as 3D. :-)
Aha… unfortunately due to the world domination hobby I’ve yet to be able to tack on the Seattle skyline (well I figured… seahawks.. etc.). I’ve come to the conclusion that having both a job *and* a demanding (though gorgeous) girlfriend considerably reduce time on Forza2 (or anything else!). Hmmm might be time to start slipping sleeping tablets into her food… mwahahahaha
@Lee, you know. If I were you I would attempt a car design like that guy did of Jessica Alba. But you can do one of your girlfriend. I’m sure she wouldn’t mind posing in various states of undress while you paint a car with her likeness. Problem solved! :-)
And on the back of the car you can make the license plate read, “Curves ahead.”
Jessica Alba…. mmmmmmmmmmmmmmmm
@Lee, I’ll see you’re mmmmmmmmmmmmmm and raise you a sluuuuuuurrrrrrpppp. :-)
Leave a Reply