Skip to content

Category: Coding

Dragging symbols in a grid with ActionScript

Some games, I’m thinking tower defense, need to give the player the ability to drag symbols around. But you don’t always want to give the player free reign to drag it anywhere. Maybe you want them to only be able to position symbols in a grid. That’s what we’ll create here using ActionScript 3.

Demo

This is what we’re going to be creating.  Try dragging the green square. It will snap so that it’s always in one of the grid squares.

How to create a random color in Java

Want to create a random color in Java? With a bit of math, plus Math.random(), it’s pretty easy.

A bit about colors

Colors on the computer are made up of a red, green, blue triplet; typically called RGB. And each of the 3 pieces can be in the range from 0 to 255. Java also allows us to create a color using floats for the values in the range of 0.0 to 1.0, or from 0% to 100% of that color. We’re going to use the floats.

As an example, pure red will have an R value of 1.0, a G value of 0.0, and a B value of 0.0.

So we know what numbers we need, but we want ’em random.

JavaScript Error ‘expected identifier, string or number’ in IE

Sometimes you get those errors that just pick at you and you can’t seem to find a solution. It happened to me this morning when testing and reviewing a JavaScript library I’m writing in IE7. FireFox worked without a hitch, but IE threw an ‘expected identifier, string or number’ error pointing to the last line of the variable declaration. Of course it didn’t help that my copy of MS Script Debugger wanted to lock up my computer.

Here’s a very shortened example of the code I was working on.