Digital vs. Analog Magic

One of the joys of watching magic is trying to figure out how it is done. Sometimes people have a good idea and sometimes they are way off. In this world of CGI and Photoshop people often think all video magic is done with digital trickery. I recently shared a Jason Latimer Buick ad that had to tell people up front there was no digital trickery due to the fact that people would most likely think that is the case. The truth is, some magic is done through digital means and others use the old fashioned "analog" methods. Can you tell which ones are which? [ad#Ellusionist]

Join Scam School's Brian Brushwood through a series of 8 pieces of magic. Some digital and some not. See if you can tell which are "analog" and which are digital.

Which ones are which? Tell me in the comments below. Flabbergasted? Share it in the comments below. Either way, let us know what you are thinking with regards to magic, both analog and digital.

Flash Friday - A Simple List

The structure of a simple listA few people who've worked with me in a programming job may have heard me talk about how a custom list should be done. For performance reasons you don't want to recreate the visual "cell" n-times. That could lead to all sorts of unforeseen problems. Instead you want only enough cells to be visual during scrolling and as you scroll through the list just bring the "cells" round to the other side. One of the people I work with, Alec McEachran, wrote a blog post  on just this topic. It is entitled "A Simple List" and I'll let you read his article and code on the subject. What is interesting about his code  for a list is he does a great job keeping the list class very simple. It keeps to a pretty narrow responsibility. He's quite good at solutions with well defined class responsibilities.

In our current project, Monster Galaxy, we have used this code in a few places. It has been modified for our purposes but at the base level described in his article the code makes custom list designs easy to implement.

Alec is a very intelligent programmer and has some other great articles on his blog. If you like what you read there you might also like to follow him on twitter (@alecmce). Of course, his twitter feed carries a lot more of his opinions and personality. It's quite fun though, I promise ;)

Of course, I have a blog as well which you are reading now and thank you for that. If you haven't done so already, follow me on twitter( @diacre ) to find out about new blog posts as well as my opinions and personality ( which you may or may not find as colorful as Alec's ). Please let me know in the comments what you think of Alec's list class. If you have a different solution that you like I'd love to hear that as well. Until next time...au revoir.

 

This Warrior's Troubled Journey

As I begin writing in my blog again I realize there has, for a long time, been a large hole in the middle of the week. My Wednesday Warrior posts have been lacking greatly. In 2010 only 3 posts were under this category and I have a feeling I know why. In an effort to change the direction of these powerful posts I would like to share the reasons I used to keep myself from writing what are usually such intimate posts.

Rough Waters In The Job Market

I had a successful 2010. I increased my value as well as finally moving into games programming and back to the west coast. However with that came great turmoil. January of 2010 saw me move my family from Wilmington to Chapel Hill, NC to work in Social Game development. That company got bought by Playdom in March and Playdom got bought by Disney in August. While my job survived the acquisition by Playdom it only lasted a few months after the acquisition by Disney. I was able to take the opportunity to find a new job on the other side of the country working with Gaia Interactive. Its a great gig and all has ended up well. So why did this stop me?

First on the list is me just trying to manage it all - and with a positive outlook. Writing these posts tend to bring buried emotions to the surface. This is usually a good thing. During this time I just didn't want to face those emotions. Second on the list is guilt. Everything continued to work out fine for me and other people are completely out of work and not having the luck I did. What did I have to complain about?

The truth is I am in the same bucket as everyone else right now. Worried about the security of my job. How stable is it? What will it mean if I lose my job? That meaning got even stronger with the other big storm that came through my life last year - health issues.

Health and the Family

My wife and I had been through a lot financially, and we've made ends meet with very little as we've had to. The job thing wouldn't have worried us as much if it weren't for the bombshell that dropped in May. Our 4 year old got diagnosed with Type 1 diabetes. All the sudden having stable, good health insurance became an all encompassing worry that hit me hard.

Context: Parenting with Type 1 Diabetes

I'm guessing people reading this don't know much about dealing with type 1 diabetes, because I didn't until I HAD TO. My wife and I have to check his blood sugar several ( read 5-7 or more if things are wacky ) times a day. This includes the multiple times in the middle of the night because we don't want him to run high all night and do long term damage or worse have him go really low and not wake up in the morning. We manage his blood sugar through injections of insulin ( we now have an insulin pump thank goodness ) throughout the day. There are no days off for this. This is our Monday through Saturday, weekends and holidays too. Traveling? We must remember the diabetes supplies, emergency glucagon injection, drinks and snacks to get the blood sugar up if need be. Of course we need to remember the stuff other parents have to remember too. [End Rant]

So I went along and I was coping, or so I thought. I was now running on similar sleep to when the kids were first born fairly consistently and I was getting worried about the stability of my studio so I was looking into other options. I guess the worry of this came crashing down on me one night when I had my first ever anxiety attack ( I thought it was more dire ) and went to the emergency room in the middle of the night.

It turns out my all the tests showed I was perfectly healthy except for one thing they wanted me to get checked out with my doctor, low blood platelets. Long story shortened, I ended up seeing a hematologist because this wasn't an errant reading. Normal range for platelets is between 150K and 400K and at one point while measured I was as low as 12K. The danger of low platelets is that your blood doesn't clot so you end up losing a lot of blood - especially if you have internal bleeding that you don't know about. Luckily I had decent health insurance with Playdom and it payed for the majority of a very expensive set of infusions ( well one is still outstanding but it should be covered ) that put me back in the normal range just before I got a new job and moved across country.

Do you know the way to San Jose?

In December of 2010 I knew my position at Playdom was going away and rather than get moved into a different position with the uncertainties of how long that would last I did something crazy and took a job in San Jose, CA working with Gaia Interactive. I started the week before New years. I can say this, the change has been really good. I love the job and I'm already loving the area but moving is a huge burden I don't want to do for a long time. Remember those health problems I spoke of? Well, it took some time to get records sent and new doctors set up for the family. I'm still having problems getting the hospital to send my records to a new hematologist so I can make sure my blood platelets are doing well - we think they sent my son's records instead. Getting my oldest in school took quite some time because of the doctors issues and California has some requirements that North Carolina didn't. I spent the first month splitting my time between work ( learning the code base mostly ) and finding a house for us to rent. My wife was still in NC so I was looking without her and relaying as much info, pictures and video as I could. That was very worrisome, especially as our move date got closer, but in the end it looks like we found an amazing house with a great people as landlords. As you can imagine, there was much more to the move than these things but those are the ones that stick in my mind as the big stressors.

2011 and beyond

Now that I am settled ( mostly ), what is the plan for the future. Well, that will come out through future Wednesday Warrior posts. The point is, with the air cleared, I am ready to create in the warrior space again. I hope this post will help other warriors see that the path is not an easy one but if you live your life through love and commitment your inner warrior has the strength to see thing through.

I have already begun some personal quests for my inner warrior and I will sharing those in upcoming posts. Also, my new home has centralized me to some great sanctuaries for personal growth. I will share those as well.

Do you have a rough journey you have been or are currently on? I'd love to hear about it. Post it in the comments or post a link to your own post in the comments below. Until then, stay strong and love on.

Essential Magic Conference 2010 and 2011?

Friday I came home from work and my wife said, "You got something in the mail from Portugal!?" I had been watching the EMC newsletter and the EMC facebook page and I knew the long awaited DVDs were coming soon. I was very excited to finally get my DVDs! EMC 2010 DVDs

The 2010 Essential Magic Conference was awesome and well worth the money without watching all the sessions. The funny thing is through video streaming and now the DVDs I can watch all the sessions over and over again. I think you can still register and get the streaming videos ( and possibly the DVDs ), however you will definitely want to sign up for the 2011 conference as soon as they announce it. From the end of the following video it sounds like they are going to have one for sure.

I know my JAMM posts usually showcase a magician performing magic in some way and this post is targeted toward magicians. So if you are a magician I hope you check this out. If the JAMM posts have inspired you to look into performing magic this is great for you as well. I only consider myself a beginner/novice magician and I got a lot out of these sessions.

Did you already know about the Essential Magic Conference? Did you watch it? If you did what did you think of it? If not, why not!? I'd love to hear your opinions.

[ad#Ellusionist]

Sunday Funnies - Insurance Execs

I know this is old, and was specific to a certain conversation that the country was having at the time. I'm just in a very annoyed at insurance BS right now and we still don't have a public option. So here is a short little video talking about who the real victims are in any talk about health care reform. [funnyordie id=041b5acaf5 width=512 height=328]

[ad#Google Adsense]

Flash Friday Refactored - IS_IN

A while back I wrote a proof of concept isIn functionality injector that seemed to work fairly decently. I even wrote some tests for it that it passed with flying colors. Being a proof of concept I never really used it and never ran into the danger of using that functionality. Recently I downloaded the trial for FDT and since it doesn't have the same type of FlexUnit integration that FlashBuilder 4 has I had to get my tests working differently. When I got the tests up an running my tests for the isIn functionality blew up in spectacular fashion. They didn't just fail, the took the whole unit test display down with them. This was the same class and tests that passed cleanly before. What happened?

It turns out messing with the prototype of Object to solve a problem is like fighting fire with a nuclear explosion. It will probably work but cause serious problems throughout the system. So, following the test driven development methodology of red, green, refactor I saw that it was a time for a refactor. Well that and it was now a red test that I wanted to make green.

I came up with a solution that I think is better. It is more flexible than before, since you can select the class you want to add the functionality to. Even better, you can remove the functionality after you add it. Since I've begun to move my code over to GitHub you can find the new code over at https://github.com/darylducharme/Ducharme-Media-Code/tree/master/src/cc/ducharme/utils. The new test class is available at https://github.com/darylducharme/Ducharme-Media-Code/blob/master/test-src/utils/IsInTests.as

You may notice that the last test - dictionaryEnumerationTest()  at this time - is new. This is the test that checks the problem that I found that was not being tested before. If you are writing tests and find a hole in your tests later, it is always recommended to add new tests to keep you from having the same problem in the future.

Hopefully, someone out there can learn from my mistakes on this occasion. Also, the new isIn class and its static functions are a whole lot more useful than what I had written before. Perhaps someone out there can put it to good use.  What do you think?

Flash Friday - Robotlegs Context

A few weeks back I wrote an article saying that I was just starting to work with AS3 Signals and the Robotlegs framework at my new job. Since then I have written a post about AS3 Signals and now it is time to write about Robotlegs. Since there is so much to write about with regards to Robotlegs I had to break out one chunk to discuss.

Robotlegs Flow Diagram showing MVCS framework

In working with the framework, reading lots of documentation and finding it central in the diagram above, I thought it best to start with the Context class in the Robotlegs framework.

Robotlegs is an MVCS framework similar to Pure MVC that relies on metadata based dependency injection. On the surface the first cool thing is that you can use the Inject metatag to populate class fields automagically. More automagic part of the framework is that mediators automatically get created when the view they are mediating gets added to the stage. Finally it has a very elegant central event dispatcher and Command pattern model that you barely need to do anything to get working. All this is possible because of the Context.

Getting [Inject] to work

// It really is just this easy
[Inject] public var obj:MyClass;

Most of the power of Robotlegs comes from the use of the Inject metatags letting the framework. However, the framework can't inject anything until it knows what to inject. This is almost entirely done in the Context and I am going to go through the main functions here. Keep in mind that all these methods also have their inverses to undo these acts but I'll let you look those up on your own. For now I'll keep it simple and we can get to more advanced usages in other articles.

Injector methods

injector.mapValue is used when you already have a class instantiated and you want to use that object as a singleton in this application context. The basic format is: injector.mapValue(whenAskedFor:Class, useValue:Object) and might look like this:

var myObject:MyClass = new MyClass();
injector.mapValue( MyClass, myObject );

If you want to do something similar without first instantiating the object, you can use mapSingleton. The format for that is: injector.mapSingleton( whenAskedFor:Class ) and the above example would be changed to this.

injector.mapSingleton( MyClass );

injector.mapClass is used when you want the injector to create a new instance of a class every time it is asked to inject that class somewhere. The format for this function is injector.mapClass( whenAskedFor:Class, instantiateClass:Class ) and if we decided against using a singleton for MyClass instances the above examples would become:

injector.mapClass( MyClass, MyClass );

That last one may seem wierd because you type MyClass twice. However, this is because you could pass in any class that extends MyClass for the instantiateClass parameter ( or implements it if it were an interface ).

Once you've used one of these 3 commands ( or some of the others I can talk about at another time ) on all the values you want to inject in your application, anytime the framework creates or manages a class object it will have the information it needs to do just that. So how do you go about getting Robotlegs to create a class object? Automagic mediators are a perfect example.

Automagic Mediators

In Pure MVC like architectures the Mediator classes handle communication between their views and the rest of the application. Since Robotlegs is an MVCS framework based on Pure MVC this is a perfect opportunity to have the framework create the mediator for you. From the Context class you only have to write something similar to:

mediatorMap.mapView( MyView, MyViewMediator );

In this MyView is a view class and MyViewMediator is the mediator designed for it. Now the application will automagically create a MyViewMediator object when any MyView object is added to the stage and inject a reference to the MyView object into it. It will also destroy the MyViewMediator object just as magically when the MyView object gets removed from the stage. I can write much more about this in an article on the Mediator/View relationship that I plan to write in the near future.

Since Robotlegs creates the mediator it can easily inject what it needs to after it creates the class. Another class type that Robotlegs creates are Command classes.

Events, Commands and tying it all together

Robotlegs uses a centralized event dispatcher throughout to keep the model, view, controller and service sections decoupled from each other and yet tying them together at the same time. One major part of the centralized dispatcher is triggering Commands. If you've read this far, I thank you and I'm guessing you already know about the Command pattern.

To set up the command pattern in the your Robotlegs Context class just use the following format. commandMap.mapEvent( eventType:String, commandClass:Class ) which might look like this:

commandMap.mapEvent( MyCustomEvent.SOMETHING_IMPORTANT, DoSomethingImportantCommand );

Now, whenever a class in the framework dispatches the SOMETHING_IMPORTANT custom event the DoSomethingImportantCommand will be created and executed. As a bonus, the specific instance of MyCustomEvent can be injected into the command with a single line:

[Inject] public var event:MyCustomEvent;

Conclusion

So this article did not have had any sexy embedded SWF files that use Robotlegs. However, this framework's strength is not about sexy SWF files but its ease of use which should make creating that sexy file go quicker. The context file is the heart of Robotlegs and using the few methods I've written about here you can use it to make a fairly robust application linked together with dependency injection.

I've purposely left a lot out of this post. This is because I just want to wet your appetite to give it a shot as well. Also, I'd like to hear what kind of questions come up for you in the comments. Finally, I could write a lot more just about the context class and favoring configuration over convention( well sort of  ), but it would just turn into a mess of words and I'd be surprised if you read this far anyway. If you did, thank you. I'd love to hear what you think of Robotlegs if you've tried it out or even if you've decided not to.

Just Another Magic Monday - Valentine's Edition

Due to the specific day of the week used for my JAMM posts, its nice when holidays and other special days line up Monday and its easy to associate magic with them. Valentine's Day 2011 is just such a day. Its Monday and there isn't much that is more magical than love. So without further ado, let me present to you a little Valentine's Day inspired magic.[youtube http://www.youtube.com/watch?v=C9cuGpqMWuA&w=640&h=390] [ad#Ellusionist] And just one more quicky, because I love Ekaterina: [youtube http://www.youtube.com/watch?v=Q_DSRCwtXxA&w=640&h=390] I'd love to hear what you think about these two videos. I know there are more out there so feel free to share those as well. Thanks for reading.

Flash Friday - AS3 Signals Basics

A short while back I mentioned a couple new open source projects I started working with at my new job. One of those projects was AS3 Signals. Since I've begun using it I've really grown to like it and I wanted to explain why. Hopefully my explanation of why will also include enough of the how. First off, have been a big fan of the AS3 event model since it came out with flash player 9. It, like many other AS3 updates, was much cleaner than the ways we were doing things in AS1/2. However, there have always been a few things that have bugged me just a little about the native event model.

I have to look at documentation to see what events a class object fires.

I can't count the number of times I am looking into a new framework, or even native classes, and I hope it fires an event but I can't just tell by code completion alone. Worse yet, sometimes important events don't even get documented so I have to search through source code to see what gets dispatched. On the flip side, if I'm writing custom classes I don't like writing documentation. I like my code to be readable like a good book, if at all possible. The AS3 event model forces you to read and write documentation. How could AS3 Signals clear up this problem though?

AS3 Signals clears up the problem of needing the documentation by having you create individual signals as objects in a class. This allows the programmer the opportunity to name the signal appropriately, thus making it easy to understand for the user of this class. Thus eliminating the requirement for documentation.

Let's give a simple example.  Let's say you have a class that loads an external file and isn't ready until that file is loaded and parsed. With AS3 Signals this is a relatively simple process.

First create the signal in the class:

public var becameReady:Signal;
public function MyFileLoader( url:String ):void{
	becameReady = new Signal();
	// you can come up with your own code here.
}

Now anyone wanting to use the MyFileLoader class can see that you have a signal called becameReady. Hopefully they can tell from just that info what it does. Or perhaps you can come up with better naming. Either way this is an improvement.

Event types are strings

Strings are flexible and easy to read ( such as in a trace or error message ). The other problem is that they are not type safe and I've had times where event type naming collisions do happen. AS3 signals takes care of this problem by both solving and circumventing the problem.

AS3 Signals circumvents the problem by having you create separate ISignal objects for each type of event you would have dispatched in the past. Even though they are all of type ISignal, they are each distinct fields on an object. For example, if I had a class controlling a form, some of its signals might look like this:

public var submitClick:NativeSignal;
public var clearClick:NativeSignal;
public var completed:Signal;

AS3 also solves the problem by having event type checking, if you are working with the native event model. I haven't worked much with this at this point so I won't get into this in this article. If you'd like to know more about this comment below and I can write about it in a future article.

Custom events and event dispatcher classes take too much code for the simplest task

We've all been there, we want to make a custom events for a project but we have to write a whole new class to encapsulate what we need. Also, if we want to dispatch these events from a class that doesn't extend EventDispatcher we need to make sure to implement IEventDispatcher. Sure, these are relatively simple tasks but they take time and you are writing code that reeks of duplication.

As you have seen above, it is really simple to create a "custom" signal. Just define and initialize a new signal. Dispatching it is just as easy.

public var somethingHappened:Signal;

private function init():void {
	somethingHappened = new Signal();
}

private function doSomething():void {
	// custom code that does something ;)
	somethingHappened.dispatch();
}

Too make the signal more custom you can send as many objects as you want in the dispatch call. I'll leave that as an exercise for the reader ( or you can exercise the comments section and I'll show you what I mean below ).

If you just want to listen once you have to write extra code

The native event model doesn't make it easy to listen once. Perhaps you want to listen to a view's close button for just one click. With the native event model you have to remember to call removeEventListener in you event handler or else your program may not work as expected and it will likely create a nasty memory leak. AS3 Signals simplifies the process with the addOnce() call.

private function init():void {
	doSomething();
	view.closeButtonClick.addOnce( onCloseButtonClick );
}

private function onCloseButtonClick(){
	view.close();
}

The previous addOnce call was so minor you might not have noticed it in the code. Really, that's all it takes. Signals are really quite easy to clean up.

Cleaning up listeners is difficult

When trying to find memory leaks, the first thing I look for is calls to addEventListener. They are usually the major culprit because it is so easy to lose track of which listeners were added to an object and for which event type. As you saw above, Signal objects have a built in mechanism for removing listeners after a single call if you want. They also have a simple way to remove all listeners from themselves, the aptly named removeAll function.

function close():void {
	closeButtonClick.removeAll();
	otherSignal.removeAll();
}

Conclusion

This article was much longer than I thought it would be. If you made it this far, thank you for reading. I hope you see how AS3 Signals is an improvement over the native event model. Once you start using Signals you'll likely find yourself using events less and less. The event model is still core to AS3 though so there are some good ways to use them together. I plan to write a ( hopefully shorter ) article on using AS3 Signals with the native event model in the future. If you have any questions, comments or requests regarding AS3 Signals please let me know in the comments below.

Just Another Magic Monday - Jason Latimer and Buick

Latimer Promo PhotographIf you've been following my JAMM posts since my old my.opera blog, you might have seen me post about Jason Latimer in the past. Today's JAMM post isn't just about him but about some alternate ways that we can experience magic in our everyday lives - advertising and promotion. Recently Jason worked with Buick on the campaign for the new Buick Verano. In the advertising Jason got to use some of his magic on screen to get across the idea of hidden keys. [youtube http://www.youtube.com/watch?v=GrhSE8g7Qhg&w=640&h=390] [ad#Ellusionist] In a more subtle bit of magic, Latimer's team also built the magic into the reveal of new car. See if you can spot the magic ;) [youtube http://www.youtube.com/watch?v=g0Lq6739x6U&w=640&h=390] If you've seen or been a part of any great uses of magic other than a straight magic performance I'd love to hear it. If you have any questions or comments about the videos above please put them into the comments below.

If you like what you are reading please follow me on twitter and/or follow my RSS feed. Also, please connect with me via google friend connect. Thanks for reading.

- Deacon