
This is just a quick little flow-chart. A project I’m working on includes a ‘Simon-says’ type game. I thought I’d share my notes on how the game logic will work.
Update: Here’s my quick prototype (before skinning)

This is just a quick little flow-chart. A project I’m working on includes a ‘Simon-says’ type game. I thought I’d share my notes on how the game logic will work.
Update: Here’s my quick prototype (before skinning)
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().
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!?
A question from a reader gave me an excuse to write a huge rant about type conversions:
I’m doing a little exercise in a book that makes a textfield in which each letter can only be entered once. Not very useful, more of a teaching thing really. However there’s a bit of code that says:
var tf:TextField = event.target as TextField;I don’t understand this at all! What the hell is
event.target as TextField? Anyway here’s the full code for context’s sake:package com.FoundationAS3.ch6 { import flash.display.Sprite; import flash.text.TextField; import flash.text.TextFieldType; import flash.events.TextEvent; public class PreventDefaultTest extends Sprite { public function PreventDefaultTest() { var tf:TextField = new TextField(); addChild(tf); tf.width = stage.stageWidth; tf.height = stage.stageHeight; tf.type = TextFieldType.INPUT; tf.wordWrap = true; tf.addEventListener(TextEvent.TEXT_INPUT, onTextFieldTextInput); } private function onTextFieldTextInput(event:TextEvent):void { var tf:TextField = event.target as TextField; if (tf.text.indexOf(event.text) > -1) { event.preventDefault(); } } } }Thanks,
-Neal
My response after the jump.
Continue reading
Since version 1.0 of a code library that I’m sure you’re tired of me talking about came out, I have been making steady updates, some of which break legacy code. I was also having trouble keeping track of which version of the library a particular demo was written for. In order to make sure that the new code library doesn’t cause unpredictable results for the old implementations I added a version check to the main class.
This version check is very simple. It checks a version number in the client code against a version number of the library (or external classes) when the main class of the library is initialized. It is also completely optional (so average users don’t need to mark up their code with version numbers).
Here’s an example:
Say you normally initialize your library using:
MyLibrary.initialize();
Which calls the initialize method:
public static function initialize():void {
// initialize library here
}
If the external code changes unexpectedly (say through an SVN update) this could cause problems that are difficult to trace. The solution is to modify the initializer to match the client code version with the initializer version.
public static const VERSION:String = "1.6";
public static function initialize(versionCheck:String = VERSION):void {
if (versionCheck != VERSION) {
throw new Error ("The version check failed! This library is version " + VERSION + ". Update your code or GTFO!");
}
// initialize library here
}
And when you run the initializer, use the version number you’re expecting.
MyLibrary.initialize("1.6");
Some things to notice with this approach:
versionCheck in the initializer, providing a version number is optional. Using MyLibrary.initialize() will still work and throw no errors.The code for my initializer in its entirety after the jump…
Continue reading