Waterproof AS 3.0 Singleton

While reading Advanced ActionScript 3 with Design Patterns I’ve once again came across the AS 3.0 Singleton solution that has to deal with the absence of private constructors (I’ll save my rage and cursings about who had the idea to remove them for now ;) ) and while the authors are using the already well known method of using a SingletonEnforcer class outside the Singleton’s package to verify that the class cannot be instanciated via the constructor they also note that this can be doublecrossed by giving null or undefined as a constructor parameter. As this is rather sub optimal I was wondering why they don’t just check inside the Singleton constructor for a null/undefined argument and throw an exception accordingly?!
I’m sure somebody else had the same idea already but here’s my idea of a waterproof Singleton class that cannot be misused from the outside (As always, if I missed any detail that accidentally breaks hell loose feel free to correct me) …

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package
{
	public class WaterproofSingleton {
		static private var _instance:Singleton;
 
		public function Singleton(singletonEnforcer:SingletonEnforcer) {
			if ((singletonEnforcer as SingletonEnforcer) == null) {
				throw (new Error("Direct instantiation of a Singleton is not allowed!"));
			}
		}
 
		public static function getInstance():Singleton {
			if (Singleton._instance == null) {
				Singleton._instance = new Singleton(new SingletonEnforcer());
			}
			return Singleton._instance;
		}
	}
}
 
class SingletonEnforcer {}

So you want to be an Indie Developer?

Some links to nine articles about the topic on ‘becoming an Independent Game Developer‘, found via Digg. Some more interesting, some less, the last one from a Mac perspective. There seems to be a lot of discussion about if it turns out to be paying off or not etc., in short, things that don’t interest me that much, I’m just creating games because I have fun doing it and I like the practical side, I’m more of a hobbyist! Either way, here are the links …

Introversion
Cliffski’s Mumblings
GameProducer.net
Lemmy and Binky
Reality Fakers
Zoombapup
BoneBroke
They Came from Hollywood
gusmueller

Learn some patterns – Advanced ActionScript 3.0 with Design Patterns

I’ve been reading this book by Joey Lott and Danny Patterson since yesterday and thought I’d loose a couple of words about it …
The book starts with a chapter about application design where it explains how to go through the analysis-, design- , implementation and testing phase. It introduces how to utilize Use Case- and Class Diagrams and then gives a lesson on how to use FlexUnit for unit testing. In the second chapter is a good explanation about why and how to use Interfaces (instead of Inheritance) and after that it goes into detail with teaching nine of the more common Design Patterns, namely MVC, Singleton, Factory/Template Method, Proxy, Iterator, Composite, Decorator, Command, Memento and State. In part 3 of the book you’ll find in-depth information about AS 3.0 features like Events, data IO, E4X and Regular Expressions.

Read more

Using Vista is like walking on thin ice … Vista’s EULA product activation worries

“…Once you activate the product, then you would assume that you are golden to go ahead and use the product, right? Wrong.

You see, even after you activate the software it will, according to
the EULA, “from time to time validate the software, update or require
download of the validation feature of the software”. It will once again
“send information about the…version and product key of the software,
and the internet protocol address of the device”.

Here’s where it gets hairy again. If for some reason the software
“phones home” back to Redmond, Washington, and gets or gives the wrong
answer – irrespective of the reason – it will automatically disable
itself. That’s like saying definitively, “I’m sorry Dave, I’m afraid I
can’t do that…”

… So basically add some regular activation annoyances to your almost weekly Windows security updates to keep you from working on the PC!
Read more here … Vista’s EULA product activation worries | The Register

Need more reasons to switch to Mac or Linux?!

Tools of the Trade Part 4: Console

This is not really a true productivity tool but I think it has enough value that it deserves to be mentioned. If you’re on Windows and work with the Command Prompt a lot, you might be fed up with the overly dull look of the black Windows command console and you look over to the Linux guys with their stylish terminals with envy. Then it’s time for you to grab and install Console, a Command Prompt enhancement that adds several useful features like multiple tabs, text editor-like text selection, different background types and – the real deal – transparent background. This alone is reason enough to throw the old console look overboard. The console font as well as window size and position can be configured. Get the latest release version 1.5 at sourceforge.net/projects/console/ for free.

Loading Zip files into Flash … yummy!

This might be old news for you but I’ve just coincidentally stumbled over an ActionScript 3 class named FZip that was written by Claus Wahlers and Max Herkender which provides functionality to load standard Zip compressed files into a Flash movie and unpack them on-the-fly. This is amazingly useful and I can see a lot of possible use for it in the future.

It also reminds me of an AS 3.0 framework that I started to write a while ago which provides all kinds of file reading and writing means. It can read and write compressed and uncompressed XML-, text- and binary files. The file writing is currently only done by use of mdm Zinc but support for other data storing methods like for example LSOs are planned and I can imagine that this could be extended with native file writing once Apollo is live. Also the compression it uses is based on AS3’s own ByteArray GZip compression but it writes it’s own custom header tag to the files to identify the file type, compression, original file suffix etc. Eventually I also started to add encryption classes so the compressed data can be encrypted before.
However this started as an offspring from my current game development project where I want to use it to keep external data files compact and it is still in beta. Now that I found FZip I’m thinking about adding support for it as well so the publish date for this is delayed a bit more.

Flash your own Converse Sneaker together

Just found this yesterday via Adobe Consulting BlogConverse – Chuck Taylor, Jack Purcell, Basketball Shoes, Design Your Own Converse Shoes. Click on the first shoe under Collection. You can design your own sneaker with your own style of color combination and even add a personalized text at the side or back. I first thought its a nice gimmick for playing but in fact you can order your designed shoe in your preferred size! I’m a big fan of classic sneakers but I have rather large feet and finding large sneakers in Japan is more than just a challenge so I thought I’d make my own couple of neatly colored Cons and order them … until I saw the Shipping in U.S. only sign! Damn! Well at least I could print my design out. Here’s my low top suede model ‘Venice Nights’ :)

This shoe designer is a nice example that shows that Flash really needs to support 3D! Imagine you could freely rotate and texture the shoe model! Wouldn’t that be cool?!

Understanding Interfaces and Polymorphism

I’ve been using Interfaces a couples of time now when needed but I never fully understood those down-sized Class construct wannabes. I knew they are useful when it is required to have an universal type for different objects but I haven’t fully grasped to scope why they are so useful otherwise. Also the fact that they can’t contain properties and only public method declarations confused me.

Read more

Tools of the Nuisance Part 1: XMLSpy

If you’re working with XML on Windows and you like your tool full-featured there’s a good chance that you have worked with Altova XMLSpy, a first of all very good and powerful XML editor but on second look becomes a nasty bugger that calls home as if there is no tomorrow.
Thats fine and good! Let them try it to call it home as long as they want, I can block it with my Firewall! It was noted by some other blogs that XMLSpy not only transfers data to check the legal ownership but also transfers private data that is none of Altova’s business, so there is good reason to block the spy (what a fitting name!) off!
But what if you want to use the Eclipse (or Visual Studio) XMLSpy PlugIn? If you block Java’s JRE, Eclipse also can’t connect to the web anymore. But fear not, there’s an easy solution. Here’s how to block off XMLSpy …
Go straight to your WINDOWS/system32/drivers/etc/ folder and add the following line to the host file:

127.255.255.255 link.altova.com

This redirects every access to link.altova.com to the local machine, thus blocking of connection attempts. With that you’re free to let Eclipse access the net while XMLSpy has to stay inside the system.

Vista and the missing compatible Software

I’ve made a partition with Windows Vista RC a while back to check out how well my used Software will run. First off I like Vista, I really do! It’s polished Aero Look is reason enough for me to switch from the vomit-colored Windows XP. But I soon realized that something important is currently missing … compatible Software! That means compatible drivers in first line. Ok, it’s still about two months away until Vista will be in the shelves for anyone (with license volume release at the end of this month) but Vista has been how long on public beta? One year? Two years?
Checking the Logitech website for a driver for my beloved MX310 mouse … nowhere to be found! Not even a working 32bit driver! Not even a word mentioned about a future driver release! How about sound? I check M-Audio’s website to get a driver for my Delta Audiophile; Their 32bit WinXP driver doesn’t install while their 64bit Beta driver installs but Vista gives me an error afterwards that it wont accept unsigned drivers! There’s a ton of other Peripherals that I’m using for which I’m sure no compatible drivers are available so I don’t even bother searching for them now.

How about applications? Flash runs fine, though it’s tool windows look a bit odd with thin borders/corners around it. Photoshop runs smooth as if it never did anything else while ImageReady’s tool palettes seem to be not style conform anymore. Illustrator then goes completely bonkers with Molasses style window-dragging and tool palettes that sometimes have round corners and sometimes not. At least Eclipse runs fine! Well, on 32bit that is! On 64bit it will spit out an error about an incompatible DLL.

That said my Vista Experience went a bit limiting so far! Dynamic Font Management is a foreign word for Microsoft too! It seems nothing has changed about how Fonts are handled! They are either installed or not. I guess I hang a little longer with MainType! Let’s hope other companies aren’t sleeping and have drivers ready until release, even if they don’t loose one word about it. It would suck otherwise!

Fotologue – The Japanese answer to Flickr

Fotologue which was Japanese only for a while has been translated into English and opened up it’s gates for anyone else around the globe! Not only does it look much more stylish than Flickr or any other photo sharing site, it’s also completely done in Flash! Check out my gallery for a quick preview of how the user galleries look.
via If Then Else

Waiting for AS 3.0 Books

A couple of days ago the ActionScript 3.0 Cookbook has been published. Obviously it’s a Must-Have but so far I resisted to buy it, waiting for some User Reviews on Amazon. Anyone else got it already? I would be interested in if many new stuff is covered or if it’s just a AS3.0 fitted version of the older AS Cookbook (though I doubt that when I read the authors names).

Then there is the highly anticipated Flex 2 book which is due for the 1. quarter next year and so it still takes a while until then. Another book I’m looking forward to is Advanced ActionScript 3 with Design Patterns, also by Joey Lott, especially because I still haven’t fully grasped patterns. Maybe this will help.