A few days ago, I posted an implementation of a Semaphore with AS3. Ever since then, something about the code just didn’t sit right with me. I’ve wanted to research and write about the Liskov substitution principle (LSP) for a while now, and I decided that I would demonstrate it with my Semaphore classes and examples. When I first designed the classes, I thought I was doing a good job, now….not so much. In fact, I think I made errors in my application architecture and overall approach.
(more…)
[Edit] The source code for this has been updated and can be seen and downloaded on this follow up post.
Flash does not support multihreading, and that’s probably good thing since managing threads can be very, very difficult; however, Flash can have a kind of concurrency when it comes to user interface, multi-user applications (e.g. games) and synchronizing animations. With user interfaces, a developer may wish to disable parts or all of the UI while asynchronous events, such as loading assets and managing various animations are executing. Within a multi-user environment, imagine a game where players share a limited amount of resources – checking things in and out as they become available ( see ‘Dining Philosophers Problem‘). Another scenario might be the need to manage many, many animations.
When it comes to concurrency there are various techniques that come to mind – The Semaphore , Java’s ReentrantLock and CountDownLatch, the Actor model, and Scala’s Mailbox. This first post will focus on the semaphore.
Something that has become (somewhat) of a lost art these days is the animated button. Designers used to go crazy with engrossing roll overs and roll outs – sometimes to the detriment of usability. Now-a-days, I don’t see many interesting buttons.
Perhaps it’s due to how button animations can be decently executed with Javascript and CSS; people are getting used to those and many designers are simplifying Flash buttons to mimic Javascript and CSS buttons. Another theory might be do to how more of Flash work has shifted towards developers handling animations. They prefer to just code the animation and in doing so can do some great things, but some things still can only done by a hand made animation.
Then….there is another theory of mine; a more subtle detail that everyone thinks, but doesn’t say out loud…
Hand animated buttons are jumpy!
In a previous post, I talked about how I use method closures to avoid AS3 events. Since then I have been using the technique extensively and I still don’t use custom events – at all. The previous example was OK, but this one is better. This is also a class I use in most my projects.
When programming, there are many things I avoid or just squash out altogether:
There are a few examples of undo & redo floating around, but I wanted to give it a shot myself. I didn’t look at anyone else’s solution and I’m glad I didn’t, because I came up with a very different and clean solution.
This is cool.
Computer Science guys know plenty of coding Kung Fu; for us Flashers, we have to either need some CS friends hangin’ around, or discover it ourselves. This time I got lucky and had both.
For some time now, I’ve been using a technique that allows me to skip Actionscript’s events and it’s really been helpful in writing clean code. Recently, prominent community developers such as Andre Michelle, Joa Ebert, Robert Penner, and Nicolas Cannasse have made solid critiques of Actionscript and generally AS3’s event model makes it onto their list of grievances. Andre and Joa have even created UIEvent to help deal with event listeners.
Like many other Flash developers, when I learned about creating custom events or dispatching Flash’s built-in events I started doing it a lot. But….. it can really be a pain. I find that frequently dispatching and cleaning up events really dirties my code. It also makes it harder to read. Also, event dispatchers can be so far removed from methods who are dependent on them, that a coder will often have to search around to find the callback. Because of this I avoid Flash events as much as possible, and here’s how I do it.
[Edit] Callbacks are also substantially faster than events: Grant Skinner’s recent optimization talk
In part one, I showed how to get started with FDT and Ant (live error checking, code hinting, dealing with the JRE error…). Part two is the start of incorporating Ant into your work-flow. I would classify these videos as beginner-ish, and starting to get into intermediate Ant.
There’s a little secret I’d like to share… I think many object-oriented programmers use encapsulation incorrectly. For years, even I was guilty.
Yes, it’s true.