Quality Reads

Monday, March 09, 2009

Over on ReignDesign...

I'll be posting on a bi-weekly basis over at my ReignDesign's blog (my new company). Here are some of the topics you can expect:
  • Flash, Flex, AIR
  • Android (Java Mobile Development)
  • iPhone (yep, packing the market with apps)
  • UX Design
Swing over and check it out.
If you are looking for RIA or Mobile Development, we've got a talented group of developers working with us. Get in touch.

Tuesday, June 24, 2008

Using DI to add a PureMVC Mediator in Flex

Classic issue with PureMVC, how do you add your mediators to your Flex components in an application at initialization. If you're not concerned with tight coupling you might add all the mediators with one command. But what if you don't want to tie all the mediator initialization together in one command? You might be thinking make separate commands for each mediator and fire it off as a PureMVC MacroCommand. Not a bad idea. It would certainly get the job done. But what about reusing the same command for each component and dependency injecting the mediator class and view component reference? Oh so clean. I love it and I think you will to.


//inside command class
public var mediatorClass:Class;
public var viewLocation:String;

override public function execute( note:INotification ):void
{
var m:IMediator = new mediatorClass() as IMediator;
m.viewComponent = getViewComponent( note.getBody() );
Facade.getInstance().registerMediator( m );
}

protected function getViewComponent( app:Object ):Object
{
var result:Object = app;
for each( var subItem:Object in viewLocation.split(".") )
{
result = result[subItem];
}
return result;
}

The viewLocation would be equal to a String like "someComponent.menu.list" where someComponent is located directly under the main application and menu is a subcomponent of that etc. etc.

If you don't know how to handle DI in a Flex application, I highly suggest you take a look at the Prana Framework. Its made a huge difference in the flexibility and extensibility of the Flex product I'm currently working on. Plus, you'll be able to handle mediator initialization in seconds with one class. :)

Cheers,
Todd

Sunday, April 27, 2008

Cantonese = Tasty

We grabbed a little late night snack after the evenings festivities at a local Cantonese restaurant. You can think of this place as the "diner food" of China. Very popular with the post bar/club crowd around 3am.

First up was a little duck.Actually, duck beak would be a little more accurate. It had been prepared in a spicy red sauce. If you don't mind spending hours gnawing at your food, this is a perfect snack (very bony).

Next we have carrot cake, no not that carrot cake.

This is actually a tuber best known from Vietnam and Laos. Its the closest thing you get to a potato in Shanghai. A little sweet with just the right amount of starch. Delicious.

Below you can see a rice paste rolled into a cylinder and mixed in a sweet, tangy sauce.

The overall effect is very pleasing. Think rice au gratin.

While I didn't have high expectation for Shanghai's culinary experience. I've been very surprised by the range of foods I've sampled since arriving here almost a month ago. I can not say all of it has been enjoyable but it certainly has been original (from a US perspective).

Cheers,
Todd

Thursday, March 27, 2008

Traveling on the Lazy

One great thing about going to Shanghai from the Eastern US is that you don't have to change your watch.



Just flip it around (assuming you don't have numbers on it!).



Its exactly a twelve-hour time difference. Brilliant!

Cheers,
Todd

PS - this might be my first post of many entitled "Traveling on the Lazy" :)

Tuesday, March 18, 2008

Google Code University

If you ever wanted to learn more about the tech. behind Google's shimmer, check out their new website Google Code University. Its aimed at students and professors but an individual interested in distributed computing will do just as well. So far the site has four main sections:
  • AJAX Programming
  • Distributed Systems
  • Web Security
  • Languages
In each section are tutorials and videos, exposing how Google is using these technologies/techniques and how you can give them a try too. A fun website if you've got some ambition and a little free time.

Cheers,
Todd

On the road to Shanghai...

I left Pier almost a month ago now. Since then I've been skiing, pub-crawling (NYC for St. Patty's Day), concert going, and traveling up and down the eastern seaboard. Time off is great but after a while it can get to be too much and you need to get back to what you love.
So, next week I'm starting my new job at ReignDesign in Shanghai, China. I'm extremely excited about this move. New language, culture, city, company...and the list goes on. Reign has a great Flash development team, I can't wait to get across the pond and meet everyone. As always, I'll be working to push the boundaries of Flash and thin client GUI design.

For all my friends and family in the US, I'll miss you guys but you're always welcome to come over and visit (mere ~18 hour flight). Wish me luck.

Cheers,
Todd

Sunday, February 24, 2008

Full Open Source Flex 3 SDK Released

The full source for the Flex 3 SDK was just released on Adobe's new open source wiki. Check it out if you're so inclined: http://opensource.adobe.com/wiki/display/flexsdk/

There were two surprises on the website:
  1. You can view Actionscript source for the AIR specific classes in Flex
  2. There's a section on Flex 4 (codename Gumbo) with some bug details
Cheers,
Todd

PS - Flex 3 and AIR 1.0 have just shipped. I think the post script topped the actual post...

Wednesday, February 13, 2008

Synchronous Service Calls in AS3

Tired of dealing with an asynchronous services in Flex? Here's a solution that can be helpful in certain situations.

Start off with a simple user interface bound to a Cairngorm-style ModelLocator Singleton:

<mx:Grid dataProvider="{ModelLocator.getInstance().myDP}"/>
<mx:Button label="Click here" click="dispatchEvent(new Event('getDP'))" />


Then Create a Controller Class that listens for the click event and calls a service:

class SimpleController{

function SimpleController(){
Application.application.AboveViewHere.addEventListener('getDP', onGetDP );
}

private function onGetDP ( e:Event ):void{
var dpService:DPService= new DPService();
ModelLocator.getInstance().myDP= dpService.getDP();//binds ArrayCollection reference from service to ModelLocator
}
}


Finally here's the service Class:

public class DPService(){

function DPService(){}

private var data:ArrayCollection;
public function getDP(){
var loader:URLLoader = new URLLoader();
loader.addEventListener("complete", onComplete);
loader.load(new URLRequest("someURL.aSweetExtension"));

data = new ArrayCollection();//create the ArrayCollection reference here

return data;//return the reference to the controller
}

private function onComplete( e:Event ):void{//get called when the service returns
var loader:URLLoader = e.target as URLLoader;
//loop over returned data and populate ArrayCollection
for each( var xml:XML in loader.data.items ){
data.addItem( xml.someProperty );//add data to ArrayCollection
}
//no need to return anything or dispatch an Event
}
}


Using this approach, you don't need to handle services asynchronously because of intelligent object reference management. We created the reference to the resulting data in the call to "getDP", Flex's data binding system will take care of the rest for us. This is a handy approach if you're binding the data directly to the UI since it can greatly simplify your controllers. In a situation where there's an error with the service, you can localize your error handling to one function in the controller in most situations.

Happy coding.

Cheers,
Todd

PS - I'm using Singleton's here for simplicity of the example. I don't suggest using them this way in an actual application. Proper MVC architecture wasn't within the scope of this article. Check out PureMVC, if you interested in learning more about Flex/AS3 architecture.