Filed under Programming

Ludum Dare 23 – Pre-Game

by

So this year I’m doing my first Ludum Dare game competition. I’m very excited and have been trying to get my system ready to go before the theme is announced at 18:00 Pacific time. I’m running down my pre-flight checklist now.

My loadout:

Note the inspirational collages and ferret poster

(note: I’d love to put a link to every single one of these but that’ll take a long time and you can google them yourself.)

Software:

  • FlashBuilder
  • Text Mate
  • Adobe Creative Suite
  • bfxr
  • Garage Band
  • Amadeus Pro
  • Art Rage

Libraries (probably won’t use all of these but they’re in there just in case):

  • FlashPunk
  • KitchenSync
  • Abstract AS3
  • AS3 Signals
  • AS3 Utils
  • AS3 Core Lib
  • AS3 Data Structures
  • Google Analytics
  • Sterling
  • zOMGamezLib (This is an old game engine that probably doesn’t even compile but I might pull some useful stuff from it. source)
Hardware:
  • MacBook Pro
  • Wacom Intuos5 tablet
  • M-Audio Oxygen
  • Blue Snowball Mic
  • iPhone / iPad (not sure what for)
  • Headphones
  • Scanner
  • Camera
  • Sketchbooks & Pens
  • Jones Coffee

You can follow me here or on Twitter @mimshwright

Matryoshka Functions

by


The other day, I was working with the Flex function BindingUtil.bindProperty(). I always have a hard time remembering which pair of arguments comes first, the ‘site’ or the ‘host’ and to be honest, the names don’t really make much sense to me. “Oh, if only this were an Objective-C project I would have to laboriously type out each name of each parameter.” I thought, “It would be so much more obvious if it were writen like Bind.property("foo").fromObject(bar).toTheValueOfProperty("foo").ofObject(baz);.”

What followed was the discovery/invention of just such a thing, a nested, super-verbose function. The function achieves this by returning an instance of an internal class with nothing in it except for the next step in the chain.

package
{
	public class Bind
	{
		public static function updateProperty(object:Object, property:String):BindSource {
			return new BindSource(object, property);
		}
	}
}
import mx.binding.utils.BindingUtils;
class BindSource {

	private var targetObject:Object;
	private var targetProperty:String;

	public function BindSource(targetObject:Object, targetProperty:String):void {
		this.targetObject = targetObject;
		this.targetProperty = targetProperty;
	} 

	public function whenSourcePropertyChanges(object:Object, property:String):void {
		BindingUtils.bindProperty(targetObject, targetProperty, object, property);
	}
}

To call this function you would use:

Bind.updateProperty(foo, "bar").whenSourcePropertyChanges(baz, "bar");

Kinda cool! I soon realized that this technique has some characteristics that Objective-C messages don’t have. For example, each step can use more than one parameter (plus they each get their own code hinting). You can also provide multiple choices for what to do next providing a sort of branching behavior.

AngleFinder.getAngleOfVector(4, 4).inDegrees() 	// 45°
AngleFinder.getAngleOfVector(4, 4).inRadians() 	// π/4

You can even do free-form stacking of functions like this.

new Calculator	(5)                    // 5
                        .plus(3)            // 8
                        .times(2)          // 16
                        .dividedBy(4)   // 4
                        .minus(1)         // 3
                        .plus(2)            // 5
                        .equals();

I proudly named these “Matryoshka Functions” after the Russian stacking dolls even though I’m sure I’m not the first to try something like this. As it turns out, they’re about 10% practical and 90% clever hack. Even though there could be some potential use for this (especially with complicated, repetitive tasks), this technique conflicts too much with the way we normally code in ActionScript. Still, I thought it was cool enough to share with everyone.

Pros:

  • Very descriptive
  • Branching and stacking effect is interesting and potentially useful
  • Code hinting shows the next step in the function as well as the parameter names
  • Looks cool!

Cons:

  • Abominable code style. Too weird to be useful.
  • Difficult to know when to stop calling functions
  • Not completing the function will produce unexpected results with no compile-time errors
  • Each step requires you to pass the parameters from the previous step

Can you find any use of these? Can you think of a more efficient way to write the functions? Any other thoughts?

Check out the source with multiple examples (FlashBuilder project).
MatroshkaFunctionDemo

IDisplayObject? – Getting around the lack of an interface for the DisplayObject in Flash

by

Interfaces are amazing things. When I was young and green, I didn’t understand their purpose, but after working with them for a while, I will defend their use to the end. I try to create lots of interfaces early on in my projects and I find that by keeping things flexible, it saves more time despite the extra typing, pardon the double entendre.

But this is not an article about why interfaces are so great. No, this is an article about the mysterious gap in the Flash Player API with regards to an interface for DisplayObjects. If you have a class typed as something like IView, there’s no way to enure that IView can be a parameter of display list functions like addChild().

Continue reading

Tagged , , , , ,

Using XML Schemas in Eclipse / FlexBuilder

by

UPDATE: After reading the entry by Misprintt on the SchemaManager and XMLDecoder more thoroughly, I felt the need to tell you all to go check it out! This is a very powerful undocumented feature of Flex (why undocumented?) that could potentially save loads of time on a larger project. Along with the rest of this article, you could automate the parsing of your XML files into bindable model classes with ease.

XML-Schema (.XSD extension) are documents used to describe the format of XML files. They are similar to DTD (Document type declaration) files but much more powerful.

xsd editor

While working on some XML documents for a Flash site, I stumbled across the XML-Schema editor for Eclipse. The editor shows the XSD as a graphical representation of the model that you’re editing that looks similar to a UML class diagram.

Here’s a great article on how it works.

Continue reading

Tagged , , , , ,

MVC cheat sheet

by

Sometimes I forget the details of whether my Model should know about my Controller and that sort of thing. I found this little MVC cheat sheet on the internet that got me straightened out in a jiffy with step-by-step instructions. The page is actually the lecture notes from one of Colin Moock‘s presentations circa the Essential AS 2.0 days but it’s still very useful. Those of you struggling with the lingo, replace Observer with EventDispatcher and ignore the junk about attachMovie. God, how did we ever write AS2!?

Tagged , , , ,