Tag: Development
Pop Quiz on Static in AS3
by Josh on Jan.28, 2009, under ActionScript, Development, Flash, Flex
Pop quiz: In AS3, are static methods & variables inherited by subclasses?
Unfuddle Your Work
by Josh on Jun.23, 2008, under Development, Web

I seem to have an addiction when it comes to finding the best bug tracker out there - I’ve never been really been satisfied with the ones I’ve used in the past, and I’m just too lazy to write my own. As a result, I’ve ended up playing and installing a bunch of different apps, trying to find the bug tracker I like the most.
Xbox LIVE Community Arcade
by Josh on Feb.21, 2008, under Gaming
This week is the annual Game Developers Conference, which I love, not for game announcements like we get with the other game shows, but for all the geeky developer stuff we get to see. There’s some awesome stuff coming out of the conference so far, and one of my favorites so far is the announcement of the XNA Community Games from Microsoft.
(continue reading…)
Using the Ternary Operator
by Josh on Jul.07, 2005, under ActionScript, Development, Flash
Just a quick mini-tutorial on using the ternary operator in ActionScript. One of those things that shows up in my search logs, so the next time someone searches for it, they should be able to find it.
The ActionScript Ternary Operator
The ternary operator, "? :", is basically a shorcut for writing quick conditional statements that evaluate to either true or false. Similar to an if/else statement, you use them to make a decision in your code, and act based on that decision.
Here's the syntax:
-
// using the ternary operator
-
(condition) ? isTrueAction : isFalseAction;
-
The ( ) around condition are optional, however they do help to clearly illustrate the condition. The code above is the same as writing:
-
// the same thing, only more typing
-
if (condition) {
-
isTrueAction;
-
} else {
-
isFalseAction;
-
}
-
Now, you won't be able to use this for something that has multiple statements after the condition like you can in an if statement, but it does have it's uses for quick little things. For example, you couldn't use it for something like this:
-
// this can't be written out using ternary operators
-
if (condition) {
-
isTrueAction;
-
var bob:String = "something";
-
goDoSomethingNow();
-
} else {
-
isFalseAction;
-
}
-
But it's great for something like this:
-
// this is a great use for ternary operators
-
(superBowlWon == true) ? gotoDisneyland() : goHome();
-
Or even for checking if a number is even or not.
You can also use this technique to set values for variables:
-
// setting a variable like this...
-
var pillToTake:String = (stayInMatrix == true) ? "blue" : "red";
-
//
-
// is the same as doing this:
-
if (stayInMatrix == true) {
-
var pillToTake:String = "blue";
-
} else {
-
var pillToTake:String = "red";
-
}
-
So, as you can see, using this operator can save you time by requiring less typing in a few situations. Now, it's not the solution to everything, but as you start using it more, you'll start to wonder how you worked without it. (Maybe not, but it'll make me feel better if I can imagine that I've somehow improved your life.)
Also, after I finished writing this, I decided I wanted to try and determine which method is faster, to see if there's another argument for learning how to use this stuff. So in a pretty informal, and un-scientific way, I ran the following test:
-
// testing ternary operator vs. if/else
-
// just copy and paste onto the main timeline, and run
-
//
-
var loops:Number = 10000;
-
//
-
// ternary test
-
var startTime1:Number = getTimer();
-
for (var i:Number = 0; i < loops; i++) {
-
var testNum:Number = Math.floor(Math.random() * 100);
-
var isEven:Boolean = ((testNum % 2) == 0) ? true : false;
-
}
-
var endTime1:Number = getTimer();
-
var totalTime1:Number = endTime1 - startTime1;
-
//
-
// if/else test
-
var startTime2:Number = getTimer();
-
for (var i:Number = 0; i < loops; i++) {
-
var testNum:Number = Math.floor(Math.random() * 100);
-
if ((testNum % 2) == 0) {
-
var isEven:Boolean = true;
-
} else {
-
var isEven:Boolean = false;
-
}
-
}
-
var endTime2:Number = getTimer();
-
var totalTime2:Number = endTime2 - startTime2;
-
//
-
trace("Total Times: \n");
-
trace("\tTernary: " + totalTime1);
-
trace("\tif/else: " + totalTime2);
-
Running this test on my PowerMac with dual G5 2.0, and 1 GB ram, I came up with the following averages after running it 20-30 times: Ternary: 201 ms, if/else: 195 ms. Now, your results may vary, and this most likely isn't the best way to test something like this, but it's enough for me to see that there is a speed difference, but it's not enough of a difference to really make me stick to if/else exclusively.
“Nudge” your files in OS X
by Josh on Jul.05, 2005, under Development, Mac
If you use SC Plugin to work with Subversion, you may have noticed that the icons used by SC Plugin to mark the status of a file aren't always up to date. Apparently, this has something to do with how the Finder handles notifications that something has happened to the items in a particular folder.
This issue has been disscussed a few times on the SC Plugin mailing lists, and the author has posted a link to a free utility called Nudge, that can be used until SC Plugin can handle the updating of the icons correctly.
Installing Nudge adds an item to the contextual menu of Finder that allows you to "nudge", or refresh the contents of a folder, and causes the icons in your SVN working copy to reflect their true status. I've been using it for a few days now, and it seems to work pretty good. If you use SVN on a Mac, you may want to check it out.
Setting up the Subversion Client on Mac OS X
by Josh on Jul.05, 2005, under Development, Mac
These instructions will guide you through the process of installing and using the Subversion Client on OS X. Later I'll do a post on how to setup your own SVN repositories, but for now it's just how to setup the client to access repositories. The initial setup takes some time, (approx. 20-30 minutes), and you will need to use the Terminal, so pay attention, and we'll get through this together. (continue reading...)
foreach($data as $donnie => $marie) {
by Josh on Jun.24, 2005, under Development, Web, wtf?!
Last night I was working on a side project some of us at mediaRAIN have been working on, and I came across the snippet of code below. It's from the NuSoap php libraries, in nusoap.php, around line 4423.

Looks like Donny & Marie have found a new line of work.
Now, I'm guilty of using iterators & other throwaway variables like bob and randy, so I can't really point any fingers. I guess next time I'll just have to start using more famous pairs though: $batman & $robin, $starsky & $hutch, etc. I mean, everyone uses bob, or foo.
I really found this more amusing than anything, so it's not a complete wtf?!. Just something to wake you up and make you laugh when you're just about to fall asleep at the keyboard again.
Programmer, or Serial Killer?
by Josh on Jun.23, 2005, under Flash, Random, Web
Just in case nobody has seen this yet, this is a short flash game to test your ability in determining if the photo of the person you're shown is of a serial killer, or a programmer.
Programming Language Inventor, or Serial Killer?
I only got 4 out of 10 right, which according to the game apparently means that I shouldn't be involved in any sort of IT hiring process.
When did THAT get there?
by Josh on May.03, 2005, under Flash

How many times have you been in a situation where, even though you've used a particular tool for years, you still manage to miss one of the coolest features that it has? And then you feel like the biggest idiot for not having seen it before?
There have been plenty of times where I've been arranging stuff on the stage in Flash, and have wanted to have an even amount of space between each object. It always drove me nuts that while there was a "Distribute" tool in the Align panel, there wasn't a way to put an equal amount of space between each object. Until a few days ago, when I found the "Space" buttons in the Align panel.
I have no idea how I missed this. After seeing the "Space" buttons in the Align panel, and looking at the panel repeatedly, I have no idea how I missed them. I thought that it may be a feature new to MX2004, but I launched Flash MX, and found them there as well. So, there goes that excuse. Looking at the panel above, it's not like the buttons are any smaller than the others, so I don't know what the problem was. For now, I'll just blame it on a small, localized black hole. (Those who saw The Simpsons last night with Ray the roofer will understand.)
So, now that I've publicly admitted to a bit of bone-headedness, I'd like to hear some of your stories (if any) dealing with the same sort of situation. Just leave them in the comments, and we'll have a little bit of a public confessional.
How to write Unmaintainable code
by Josh on Apr.27, 2005, under Development, Flash
As a followup to The Best Naming Convention, Ever!, I now present to you instruction on "How to write Unmaintainable Code"
Tips include:
- Buy a copy of a baby naming book and you'll never be at a loss for variable names. Fred is a wonderful name, and easy to type.
- Use foreign language dictionaries as a source for variable names. For example, use the German punkt for point. Maintenance coders, without your firm grasp of German, will enjoy the multicultural experience of deciphering the meaning.
- Use _ and __ as identifiers.