Tcoz Tech Wire

Discoursing on trends and technologies interesting to Tim Consolazio, sole proprietor of Tcoz Tech Services, specializing in Flash/Flex/Air, iPhone, Facebook, Twitter, and related technologies.

"Technology from an indie software developer's perspective".

Monday, June 22, 2009

TcozTwitter: A Twitter Client using Adobe Air and the Flex Mate Framework - Day 7: Running on the iPhone...really?

This post covers my progress developing a Twitter client using the technologies mentioned in the article title, but also takes another interesting turn. I've been working on the side with Citrix to understand their latest XenApp Server product, and how a Flash/Flex/Air developer might be able to leverage it. To this end, I decided to branch my Air code base, and use what I've already done to drive forward a version of TcozTwitter that could be delivered on the iPhone...or any mobile device for that matter.

Notice I said “branch”, not “start all over again with a different technology”, and “any mobile device”, not just “iPhone”. Those are the important things to get here. More on that in a minute.

If you're interested in the history, links to all the previous blog articles are at the end of the article.

To summarize, here's the “thin line” of technologies you'll need to be familiar with, if you want more detailed summaries, look at the links at the bottom of this article:

Amazon EC2 Cloud and S3. EC2 is essentially a vast pool of processing power that you can isolate a piece of to run whatever you need. I frequently liken it to a ball of clay; you grab a chunk and shape it the way you want; when you're done, you take a snapshot of the configuration (so that you can “restart” it from where you left off), and put the chunk back on the bigger ball. S3 is “Simple Storage Service”. It's basically a huge pool of storage space that you can access via an API or one of many downloadable clients. When you take your “snapshot” of your “chunk” (or in EC2 parlance, when you “bundle” your “instance” into an “AMI”), the AMI is saved to a “bucket” (essentially a directory) that you've previously created in S3. When you “restart” your instance, you point to the configuration file that gets stored with your AMI data, fire it up, and there ya go.
XenApp Server and Desktop. There's a lot to this technology, but I'm focusing on the iPhone-tweaked version of the product, which you can read about here. Briefly, XenApp and Desktop are server-side software that “virtualizes” applications and allows you to view them over a variety of different clients. You install whatever app on a server—any technology that the server supports is fine—then “publish” it via the XenApp software so that it can be accessed remotely by Citrix Viewer and Receiver clients. Citrix has published an AMI in the EC2 cloud that you can use to experiment with. Remember, an AMI is a saved configuration, ready to go. All you need to do is go the cloud, fire it up, install your app, publish it, and remote clients can access and run it. The Citrix XenApp AMI is a demo that times out in three months; plenty of time to learn your way around.
Flex/Air, and Mate. Flex is an ActionScript 3 component framework used to build applications that run in the Flash player, Mate is a Flex-specific framework, heavily leveraging MXML, to simplify and organize building applications with Flex and ActionScript 3. I'm using Mate purely to familiarize myself with it. I'll say this; compared to other frameworks, it's pretty easy to get your head around, and it does simplify a lot of tasks. I have some concerns, but that's true of any prescribed development approach.
The iPhone. Enough said about that I think, and then some.

You'd be surprised, once you know exactly how it all works, how easy it is to set this all up and get basic applications working. I can publish an app, or an app update in a matter of minutes.

Here's some screenshots of my Twitter client, running on the iPhone, using all the above mentioned technologies:








It really works, even over EDGE on an OG iPhone (as I write this article, I'm actually expecting the delivery guy with my new 3GS 32mb Black. UPDATE, I have the new iPhone, and the Citrix stuff runs great over the 3G network). I leave it up and running on my iPhone while it's docked to see my tweets come in without any page refreshes and whatnot.

I also have to say, Citrix' luminaries Chris Fleck and Ray Yang have been great. When I started my experiments, I pinged them with a few questions, and they've been supporting my efforts with tech info and advice ever since, because they're interested in my perspective on these technologies.

It's that perspective that, perhaps, makes this all interesting, so much so that TechCrunch published a story on my findings that stayed on the front page of their site for weeks and sparked a lot of debate, mostly revolving around “There's no need for Flash on the iPhone,” and “why don't you just build a native app”. Flash is a great candidate for building mobile apps. The industry just seems to have a variety of issues that prevent it from getting out there on mobile devices, and I have good reason to believe they're not primarily technical ones.

Anyways, I'm an independent developer; in a nutshell, that means I go from contract to contract, building various kinds of applications for various kinds of clients of all sizes. I've worked for Microsoft, Viacom, Thomson Reuters, IAG Research, American Express, CitiGroup, IEEE/Spectrum, and a slew of smaller shops and startups. I'm pretty proud of my portfolio, and I work hard to stay cutting edge; I run servers to host all kinds of development environments and server software, like Flash Media Server, TomCat, BEA WebLogic, MAMP, Red5, Blaze, Ruby/Rails, .Net, Air, SVN, FTP, mySQL, SQL Server, Oracle Comm. Edition, etc. etc.

It's a lot of work, and isn't cheap; sure I write it off, but I have to do the cash layout, and admin/maintain them. IMHO, it's necessary; a good independent developer should know how to put together a good development and staging environment in just about any technology.

So, enter the Amazon EC2 cloud. Now, I can spin up instances of virtually any kind of development environment...install this and that software/app/etc...save the configs and shut them down...for about 10 cents an hour. After doing the math, that works out to about half what I pay now for a fully dedicated hosted box at a solid host company, and that's only if I leave it up and running 24/7. It's WAY flexible. For staging and development testing, it's fantastic.

However, most of what I do for a living involves Flash development. I love the iPhone and have learned Objective C, got my business accepted into the dev program—it turned out to be more than a matter of just paying for it to my surprise—and so on. But I've been working with Flash for a decade, and it's a big disappointment that Flash doesn't run on it.

Enter XenApps, which Citrix makes available as a demo AMI config in the EC2 cloud. All I have to do is select the AMI, launch it, and I'm looking at a clean build of Windows Server 2k3 with XenApps, Desktop, and all that; everything I need to work with to see if I can deliver a Flash/Flex/Air application to an iPhone.

I settled on Air, mostly due to the fact that Air doesn't deal with browser security and sandboxes the way that Flash/Flex do; Air is a native runtime, with it's own encrypted data store and access to NativeWindow and other elements that make it a fairly powerful RIA desktop development environment. Crossdomain and such isn't a hassle as well. You can also publish an Air app (which, on Windows, is an .exe) in a very straightforward way from the XenApp environment, as opposed to using AppViewer, which is a .Net app Citrix distributes that you run in lieu of your actual SWF by pointing it at the web page that embeds it. It works and works well, but I figured why bother with web pages and such if I can just run my Flash app in a native runtime environment without the involvement of the browser footprint.

The connection should be evident; there I was developing a Twitter client in Flex Builder, and publishing it to Air, using the Mate framework. So I decided to marry the two efforts, and see if I could branch my slowly developing Twitter app—it's hard to find spare time, but I fit it in now and then—and see if I could tweak it for delivery to the iPhone via XenApps.

Yay verily, it worked; I installed the Air runtime on the Windows instance, installed my Air TcozTwitter client, published it through the XenApps server, and pointed the iPhone Citrix Receiver at it, and there it was, touch enabled and all. True, I had to rethink the UI in terms of the iPhone. I've had people say that Flash apps won't port directly to the iPhone because they use mouseovers and such—think about it, the iPhone doesn't have “fingerovers”, which is interesting—but that's true of any technology no matter what. As a UI developer, you have to look at the device, consider the interactivity, and develop your app, using your given technology, in that context. If you factor your code well and the UI is truly abstracted, this isn't that big a deal though at all, certainly a heck of a lot less work than writing the whole thing all over again in Objective C...and then Symbian...and then Android...and then Windows Mobile...and then Blackberry...and whatever else winds up getting cranked out of BigTech Labs XYZ.

Here's points I found to be VERY interesting about this manner of development:

I'm not an “enterprise”, I'm an independent developer. But, I don't just write code for clients, I build things off to the side to keeps my chops fresh and who knows, maybe make some money. I find that this technology, although created by Citrix which is typically associated with “enterprise”, works for me. The Citrix guys seemed to find that interesting too. A library of demo apps that I can bang off a single EC2 instance is also a powerful demo tool for landing contracts. As I mentioned once before, I could probably get work just by having put all this together.
With just UI refactors, I can roll out the same codebase to any mobile device that Citrix has written a Receiver for. They've covered a number of them, see their website for more info.
The XenApps “tweaked” version I'm working with, via the Receiver, presents your apps as a selectable library; so, the user downloads ONE app (the phone-specific Receiver), and they can access ALL the apps that I publish though XenApps.
Consider the above...all I have to do, to deploy a new app to my entire userbase, or update one, is install it on my EC2 instances, which you access via RDP or the Citrix Receiver desktop app (I use the Mac version). No app store approval iterations. It'll be interesting to see how this shakes out.
Because the app runs on a regular server, I don't have the development restrictions inherent on the iPhone. I can make any number of network connections of any kind, store data in a variety of ways locally, and whatever else I need to do. The available technology I can use to drive my apps is essentially unlimited.
For proving out concepts and getting user reactions, this can't be beat. I can build apps rapidly in one codebase, get them deployed to all kinds of devices, and see what users think. What hits on a Symbian may not hit on an iPhone. Depending on the reaction, I can decide to build a native app, or abandon the effort for a given platform.

There are some things I have yet to figure out, the Citrix guys say they are interested in helping me find solutions:

Encrypted data store in the Air runtime is having some issues; I believe these are probably related to the permissions that XenApp is using to run apps under; some server config will probably solve this, if not, I can always just dump everything to a SQL DB or some such.
iPhone mechanisms, like the auto-complete for text, the new cut 'n paste, and such, don't work, because the app isn't actually running on the phone. Fixable, because I can just build the capability into the application, and just make sure I emulate the iPhone look 'n feel. The investment of time can in fact give me the same look and feel consistently across any device...nice for my end users on different platforms, and of course very useful looking forward to things like NetBooks and touchscreen e-readers.

Will I abandon building native apps for the iPhone, and whatever else I find the time to learn how to build apps for? Of course not. There's money to made out there, and different development technologies is something I'm interested in. So, the Objective C book and Xcode will still take up space on my hard drive, and be frequently used.

But, if I work with a client that needs apps rapidly deployed to a variety of devices, without going through the rigor of building multiple versions and maintaing multiple code trees, will I be glad that I learned how to do this...and, will I continue to ensure that apps I build are constructed in such a way where I can branch and get a version running on the iPhone this way in relatively little-to-no time?

You bet. Citrix has most definitely found a place in this independent developer's toolbox.

I wonder how many other contract Flash developers have said that.

As always, thanks for visiting.

Article Links:

TcozTwitter: A Twitter Client using Adobe Air and the Flex Mate Framework: Day 1, Day 2, Day 3, Day 4, Day 5, and Day 6.

Flash/Flex...on the iPhone? Initial Exploration, Follow up with Citrix.

Why the Amazon EC2 Could and S3 is a great thing for the independent developer, Article Link

Labels: , , , , , , , , , , , ,

Wednesday, June 17, 2009

TcozTwitter: A Twitter Client using Adobe Air and the Flex Mate Framework - Day 6: Running on the iPhone

It's been a few days since my last post, but I've been VERY busy. Swift3d V6 is out (it's great 3d modeling and animation software, very Flash and Papervision friendly), I'm still skilling up my iPhone dev chops, I'm digging in to Flash Media Server 3.5.2, my current contract is coming to release (V1.0 of Thomson Reuters Insider), and...well, you get the idea.

If you've been following my blog, you know I've been working with Citrix to use their XenApps image in the Amazon EC2 cloud to deliver Flash/Flex/Air apps to the iPhone using the Citrix Receiver. You can view the previous post links on the right of the blog page, or search for "iPhone" and "Citrix" tags to review previous posts on how I'm going about this.

I've got the issues sorted for the most part: design parameters for an iPhone app delivered this way, how to get rid of the Adobe Air EULA so that users don't have to click through it, and so forth. I've even got ads integrated (I'm running an OpenAds server that I've set up a couple of campaigns on for friends that own businesses...free ads for them, proof of concept for me).

I'm going to put up a full blog post on the issue, but for now, here's a picture of what I'm looking at on my iPhone. I just leave it up in my iPhone doc, and see my tweets come in without any refreshes; it's a fairly real-time twitter client. I've even tried it over the EDGE network, it works fine (remember, that client is actually not running on the iPhone). No awkward refreshes like standard VNC or RDP, etc.

With this as a base, adding features to complete the functionality is pretty straightforward. I'll be adding a login screen (right now it just uses my creds), a post-tweet screen, a fancy loader, and all that. But it's all just Flash development at this point, the mechanism to deliver it to the iPhone running as a native app, all I need to do is update the Air app on the EC2 cloud instance to deploy a new version; users of the Citrix Receiver won't have to update the app, they'll just have to restart the Citrix client.

Pic below, detailed blog post in next couple of days. Interestingly enough, there's not that much to tell. If you know how to put it all together, it's actually pretty easy to set it all up.

Labels: , , , , , , , ,

Friday, June 12, 2009

TcozTwitter: A Twitter Client using Adobe Air and the Flex Mate Framework - Day 5 : Multiple views, control bar, and Mate wishlist item

This is a continuation of a series of articles on my experiments with writing a Twitter desktop client using the Twitter API, the Mate Framework for Flex, and Adobe Air. Previous blog posts are here at Day 1, Day 2, Day 3, and Day 4.

This time around, I decided to get two views working: the public timeline, and my own @tcoz_tweet timeline, the latter of which is made up of my own tweets, and tweets by the members I follow.

To accomplish this, clearly I needed a way to organize different list views, and a way to switch between them. From a UI perspective, naturally a control bar seemed to be the way to go. Anticipating this, I'd already left some space at the top of the application above where tweets appear, and it turned out to be just enough; 35 pixels to be precise.

A quick look at the current state:



Starting to finally look like something isn't it? This might not be my final design, but it serves the current purpose, and doesn't look all that bad. Notice the "next" button, which currently doesn't do anything--there's nothing to go "Next" to yet--but from a forward-looking perspective, I plan on integrating search, profile views, that sort of thing. It seemed like a good idea to assume I'll need more room than what's in that one strip.

If you're curious how I'm doing the skinning, note that there are no embedded or static images of any kind being used as backgrounds for the tweets, the buttons, or any other such thing; everything is done with the AS3 drawing API. The matrix object makes gradient fills very easy--well, compared to how they used to be--with the createGradientBox utility method. Here's a sample of how I put together gradient fills:


var matrix : Matrix = new Matrix ( );
matrix.createGradientBox ( width, height, Math.PI / 2 );
graphics.beginGradientFill ( GradientType.LINEAR, Model_Config.getInstance ( )._tweetColors, [ 1, 1 ], [ 128, 255 ], matrix );
graphics.drawRect ( 0, 0, width, height );
graphics.endFill ( );


Note that I'm pulling the colors for the gradient off of my Model_Config object and applying it to the graphics object of my view. In my coding style, Models are frequently singletons, and if you recall from a previous article, I populate this model with data from an XML file, which the user can edit to alter the appearance of certain UI elements, like the background colors of tweets (again, thanks for the inadvertent feature request iJustine). Some may say that I should be accessing the data through a proxy, and that accessing Models directly is evil, and in a larger effort, I'd tend to agree. But the deeper I get into this app, the simpler I think it is. Writing a twitter client with even some semi-advanced features isn't all that difficult.

Now, you notice that I have two buttons that matter at this point: My Timeline, and Public Timeline. Click one, see one, click the other, see the other. Again, from a previous article, you know that I'm pulling collections of objects from the Twitter API, and binding them into lists. To toggle these list views, I decided to use a flex ViewStack, and it works like a charm.

If you're not familiar with ViewStack, it's a component that makes it easy to swap the currently visible view. All you do is set the selectedItem property on it to bring the desired view to the top: 0 is the first item in the stack, and so on. Here's the code:


<mx:ViewStack id="timelineViewStack" width="100%" height="100%" creationPolicy="all">

<mx:Canvas label="My Timeline" width="100%" height="100%" backgroundAlpha="0">
<mx:TileList id="userAndFriendsList" backgroundAlpha="0" borderStyle="none"
height="100%" width="100%"
itemRenderer="com.tcoz.twitterclient.renderers.Renderer_Tweetr"
paddingBottom="0" paddingTop="0" paddingLeft="0" paddingRight="0" />
</mx:Canvas>

<mx:Canvas label="Public Timeline" width="100%" height="100%" backgroundAlpha="0">
<mx:TileList id="publicList" backgroundAlpha="0" borderStyle="none"
height="100%" width="100%"
itemRenderer="com.tcoz.twitterclient.renderers.Renderer_Tweet"
paddingBottom="0" paddingTop="0" paddingLeft="0" paddingRight="0" />
</mx:Canvas>

</mx:ViewStack>


Pretty simple; the ViewStack is a top-level MXML wrapper. In it, I've got a stack of canvases which act as the swappable views. Inside those canvases, I have my TileList components, which is what I bind my data object arrays to. The TileList takes that array of objects, creates a specified ItemRenderer for each one, and passes it one of the data objects, which has properties that map to a tweet, like name, thumbnail url, etc. The specified item renderer receives that object, which is automatically available as instance name "data", and binds the properties to the UI elements where I specify. Here's the internal of my ItemRenderer, which will power all of the TileLists that display tweets (properties like x/y and such omitted for clarity):


<mx:Image source="{ data.user.profileImageUrl }" />
<mx:Text text="{ data.user.name }" />
<mx:TextArea text="{ data.text }" />


That's it! The Flex framework makes this pretty easy. It's completely extensible: I make a new API call, like search for tweets, I get back an array of objects from the Tweetr, or my own (I'm currently using both) library. I drop another TileList into the ViewStack, and bind the data to it. I put up a button, which when clicked, sets the selectedItem property of the viewstack, which makes the desired view appear.

Now, onto something I discovered about Mate. First of all, I have found myself really liking that when I need to dispatch an event from anywhere at all, all I need to do is either do it from a view or from a Mate GlobalEventDispatcher, set it to bubble, and add the handler to my EventMap, which directs it as needed.

But...there's something missing. Take a look at this code from my evolving EventMap:


<mate:EventHandlers type="{ Event_ControlBar.SELECTED_MY_TIMELINE }" debug="true">
<mate:MethodInvoker generator="{ Manager_States }" method="changeTimelineState" arguments="{ someComputedArg }" />
</mate:EventHandlers>

<mate:EventHandlers type="{ Event_ControlBar.SELECTED_PUBLIC_TIMELINE }" debug="true">
<mate:MethodInvoker generator="{ Manager_States }" method="changeTimelineState" arguments="{ someComputedArg }" />
</mate:EventHandlers>


Note that both of these event handlers call the same method on the same Manager object.

I would very much like to have been able to do something like this:


<mate:EventHandlers type="{ Event_ControlBar.SELECTED_PUBLIC_TIMELINE | Event.ControlBar.SELECTED_PUBLIC_TIMELINE }" debug="true">
<mate:MethodInvoker generator="{ Manager_States }" method="changeTimelineState" arguments="{ ( someComputedArg ) }" />
</mate:EventHandlers>


The difference here is, I've set the event handler to accept two events as the trigger with a bitwise OR. So, if either of those events are received, the argument can be determined and passed along to the Manager. This would also be useful for bitwise exclusions, and so forth.

As far as I can tell, there is no way to do this directly in the EventMap in Mate. Every time you need to receive a different kind of event, even if it's the same arguments, same Manager, same method, etc., you have to create an entirely new MXML fragment and place it in the EventMap.

In AS3, I'd typically do something like this:


myObj.addEventListener ( MyEventClass.EVENTONE, onMyEventClassEvent );
myObj.addEventListener ( MyEventClass.EVENTTWO, onMyEventClassEvent );

private function onMyEventClassEvent ( event : MyEventClass ) : void
{
if ( event.type == MyEventClass.EVENTONE )
// do something
else if ( event.type == MyEventClass.EVENTTWO )
// do something else
}


I'm looking further into this, but so far, after searching through the docs and such, I've found no indication that you can use a common handler for multiple event types. It might be possible with a standard if statement or some such, but I was really hoping for the elegance of bitwise operators.

This is one of my misgivings about Mate, and MXML in general; it's VERBOSE. WAY more verbose than straight code. I suppose that might just be a point of view; some people may prefer the hierarchy of nested markup. At this point in time though, I don't.

Anyway, that's it this time around. As always, thanks for visiting.

Next up: refreshing Tweet lists, ensuring I only add the most recent tweets, which means, either issuing a request based on the time of the last received tweet, or just receiving the bulk and trimming off the ones that I've already got in my list.

Labels: , , , , , , ,

Monday, June 8, 2009

Flex Mate: If you've asked "Why don't my events seem to be getting to the EventMap", this may help. Consider performance though.

I see this a lot out there, so figure a blog post might be very helpful to developers exploring the Flex Mate framework. If you're not familiar with Mate, go to the ASFusion Mate site.

People hear how great and lightweight the Mate framework for Flex development is, and it is interesting to work with (though it does have its issues...however, what framework doesn't). Invariably, every developer crashes into the same problem:

"I have a class that extends EventDispatcher. I dispatch an event from it. The EventMap has the correct type of event registered in its MXML markup, I've got my Manager set up to handle the logic for the event, exactly as it shows in the examples. I then dispatch an event from the Manager. WHY DOESN'T IT WORK the EventMap never seems to see the event ARGH!".

The first thing to note is, there's no explicit listener set up for your event handling. Mate just seems to magically know that you dispatched an event.

Naturally, there's nothing magic about it. The general idea is, if you dispatch an event, it needs to be told how to find a handler. Typically, you just set up an addEventListener for the type of event on the object you want to listen for the event from, then from that object, you dispatch the event. It's a many-to-one thing, but it's explicit. If no object has set up a listener for that event, then even if the event is dispatched, nothing will happen.

However, events have an argument you may have seen: "bubbles". By default, this is set to "false", which is how the vast majority of developers are used to using it. As the name implies, if it's "false", the event will not "bubble".

But, if "bubbles" is set to "true", then the dispatched event will "bubble" up through it's object hierarchy until it finds a handler set up to listen for that event.

From the documentation (note that ancestors mean "objects that came before", e.g. parents):

In the bubbling phase, Flex examines an event's ancestors for event listeners. Flex starts with the dispatcher's immediate ancestor and continues up the display list to the root ancestor. This is the reverse of the capturing phase.

For example, if you have an application with a Panel container that contains a TitleWindow container that contains a Button control, the structure appears as follows:

Application
Panel
TitleWindow
Button

If your listener is on the click event of the Button control, the following steps occur during the bubble phase if bubbling is enabled:

Check the TitleWindow container for click event listeners.
Check the Panel container for click event listeners.
Check the Application container for click event listeners.


So now you get an idea of how the EventMap works. The EventMap is put in the top-level Application (or WindowedApplication for Air developers). So, all events need to "bubble" to the top, so that the EventMap, which has the listeners, will receive them.

So you might think, "great, put in my EventMap listeners, then, just set all my events to bubbles=true and voila."

If only it were that simple; notice in the first line of the documentation quote, it says, "Display List". If you're not familiar, here's the relevant documentation blurb regarding the display list and events:

Every object in the display list can trace its class inheritance back to the DisplayObject class. The DisplayObject class, in turn, inherits from the EventDispatcher class. The EventDispatcher class is a base class that provides important event model functionality for every object on the display list. Because the DisplayObject class inherits from the EventDispatcher class, any object on the display list has access to the methods of the EventDispatcher class.

This is significant because every item on the display list can participate fully in the event model. Every object on the display list can use its addEventListener() method--inherited from the EventDispatcher class--to listen for a particular event, but only if the listening object is part of the event flow for that event.


In other words, if the object you dispatch the event from is not in the display list...so, if your object does not inherit somewhere along the way from DisplayObject, and hasn't been added as a child to some other object that inherits from DisplayObject, which ultimately can trace its DisplayObject ancestors back to level where the EventMap is, it'll never get there.

Why is this a problem? Say you dispatch an event from a DisplayObject that is in the display list that resolves to the EventMap. So far so good, the EventMap will pick it up, and send it to a specified Manager to run a function and complete the handling. Now, from that Manager, after it does something, like set properties on a model or whatever, you want to dispatch an event, the handler for which has been set up in the EventMap. The Manager extends EventDispatcher, the event is set to bubble.

No dice. The EventMap won't see it, because the Manager is not a DisplayObject; it's not in the display list.

The solution: in your non-DisplayObject and/or not-in-the-display-list object, declare a public variable of type GlobalDispatcher (I usually call it "dispatcher"), and either instantiate it in the constructor, or right before you dispatch your event. Use it to dispatch your event. The EventMap will now see it.

If you've never encountered GlobalDispatcher before, it's not that terrible an oversight; it's not a Flex thing, it's a Mate thing. If you've looked at the Mate framework source, you find it in the "core" namespace. The comment in the code indicates:

/**
* GlobalDispatcher is the default dispatcher that "Mate" uses.
* This class functions as a dual dispatcher because we can register to
* listen an event and we will be notified if the event is dispatched in
* the main application and in the SystemManager.
* <p>Because SystemManager is the parent of all the popup windows we can
* listen to events in that display list.</p>
*/

Example code:


public class Manager
{
[Bindable] public var dispatcher : GlobalDispatcher;

public function Manager ( )
{
dispatcher = new GlobalDispatcher ( );
}

public function doSomethingThenDispatch ( data : Object ) : void
{
dispatcher.dispatchEvent ( new Event ( Event.SOMETHING_EVENTMAP_IS_LISTENING_FOR ) );
}
}


Note that because you are using a GlobalDispatcher, Manager doesn't have to extend EventDispatcher. You may want to get a little more OOP about this, inheriting from a base Manager class that has the global dispatcher on it already, and then just either override a function in an extended class or just use the dispatcher parent instance directly, whatever floats your boat.

I wonder about this kind of global dispatching and the wisdom of it from a performance perspective; I suspect that bubbling all your events through the entire display list in an application can degrade performance, and that seems to be a supported notion. Take a look at this quote from the April 2009 issue of Adobe's Edge newsletter:

There are performance considerations with this approach. Because we are relying on bubbling to communicate our event all the way up the Display List, Flash Player must broadcast an event all they way through the ancestor chain of the component that dispatched the event. If our component is buried deep inside many HBoxes, VBoxes, and Canvas containers, then our event could bubble through hundreds of objects before it reaches the top. If our application is communication-heavy, the overall performance of the application could degrade when a large number of messages need to be passed on. This is a factor developers must consider when choosing this solution

An experienced Flex/Air developer may say, "well of course. Don't build apps that nest heavily. Break up your event maps. Only bubble events that are logical to bubble". Fact is though, people use frameworks because they want a prescribed model; the EventMap is EASY. So just nest your containers based on what works fast, and bubble the events to the EventMap. Bang. The bigger your app gets, the more this will degrade performance, until you eventually top out some ceiling and it all comes down.

So, it would seem that a best practice for Mate would be, even more so than usual...CAREFULLY NEST CONTAINERS, and, don't use the EventMap, or numerous EventMaps, for all your events. ONLY bubble events that are otherwise not practical to set up dedicated listeners for, i.e. for components that you would might consider taking the easy way out with things like "this.that.that.that.addEventListener", and that sort of thing. There's no reason that you can't use the standard ActionScript model, and the Mate model, to get the best of both worlds and build a solid application.

As always, thanks for visiting.

Labels: , , , ,

Wednesday, June 3, 2009

TcozTwitter: A Twitter Client using Adobe Air and the Flex Mate Framework - Day 4 : Getting into Authentication

This is a continuation of a series of articles on my experiments with writing a Twitter desktop client using the Twitter API, the Mate Framework for Flex, and Adobe Air. Previous blog posts are here at Day 1, Day 2, and Day 3.

This time around, I started researching the dreaded topic, "Authentication". That is, in order to do anything really meaningful on behalf of a user, an application has to ask for your username and password, and one way or another, send it to Twitter for processing so that they can tell you "this is a known user, here's access to their stuff".

This is an interesting conundrum, since once you've installed a custom application and started using it, there's very little to prevent the application from taking your account information and sending it to a non-Twitter service. After all, you're just filling out a username and password form that isn't on the Twitter site, and clicking a button saying "sign in". The application could be sending that data anywhere. More tech-savvy users will know to use bad credentials first and monitor http calls carefully; if you see something not going to Twitter, something could be fishy.

There are social network apps and widgets out there that do this: IMHO YOU SHOULD NOT USE THEM. You are essentially giving your username and password to an unknown entity. Assurances aside, why take the risk? There is a better way...keep reading.

Let's assume that I'm not going to do anything nefarious with my own credentials. Unless I develop full-blown paranoia of some kind, I'm relatively certain that me-the-developer isn't going to compromise my Twitter account.

A visit to the Twitter API Wiki to review Twitter authentication reveals that there are two ways for an application to go about authenticating a user for access to their account-specific info: OAuth, and Basic Authentication. In brief layman's terms:

- Basic Authentication is a widely supported authentication mechanism involving sending the user's username and password encoded as Base64 via an HTTP POST. I won't get into what that means exactly here, suffice to say that it is a standard way of sending values to a web server, with those values represented in such a way that certain kinds of characters will not confuse or compromise the authentication mechanism. Such a transmitted string might look like "QWxhZGRpbjpvcGVuIHNlc2FtZQ==". While this may appear to be "secure" to the eye, since it's not the original string value (like your password), it isn't at all, because Base64 is easily decoded into it's original value. In other words, your credentials can be intercepted, decoded, and revealed.

Twitter allows the use of Basic Authentication, but they clearly don't like it. They're considering removing it in favor of OAuth. On their site, they say "We would like to deprecate Basic Auth at some point to prevent security issues but no date has been set for that."

So me, I'll use Basic Authentication will I'm dinking around with nailing in the UI for my Twitter client. But when I get ready to go live, I'll definitely want to switch to OAuth. It might very well for this reason that Twitter leaves Basic Authentication lying around; it's just easier to develop an app if you don't have to deal with OAuth.

- OAuth (useful beginners guide here) is an authentication protocol that allows users to approve applications to act on their behalf without sharing their password. The basics of it are this; the developer has to inform Twitter directly that they have created an application that will be making calls into their API that require authentication. You fill out the form and register your app at Applications that User Twitter page. Twitter returns to you tokens to be used when requests are being sent back and forth. A Token is generally a random string of letters and numbers that is unique, hard to guess, and paired with a secret key to protect the token from being abused.

The flow then goes something like this: you, the user fire up your Twitter client. If you have not already done so, the Twitter client should direct you to a web page where you can say, "Yes, allow this application to access my information based on my id" (not your username and password). From that point forward, the application sends its key, along with your unique Twitter-system user id, to the API. The Twitter system looks at the key, and the ID, and asks, "has this user authenticated this application". If the answer is yes, the interaction proceeds, if not, it's declined. Remember, this key is coupled with another secret token, so just intercepting the in-transit data won't work (unless the hacker has obtained your secret key somehow).

OAuth is considered sufficiently secure for this sort of interaction, and prevents the problem I described before about being able to capture user credentials, since the user never directly provides credentials to the application. Yes, once you approve the app at the Twitter site, the application can do wonky things, like making bad tweets on your behalf, but as soon as you see that you can either de-authorize the app, or Twitter will ban the application entirely by revoking the tokens. OAuth is most definitely what you should be looking at if you intend to release any kind of Twitter client. It is a VERY common security paradigm, e.g. Facebook uses it, so any developer getting into building apps for social networks should definitely get their head around it.

So, that aside...like I said, I want, for now, to be able to make calls as simply as humanly possible into the Twitter API, I don't care if they're secure or not at this point.

To that end, I found the tweetr ActionScript 3 library. By just copying the code in their example "Retrieving One Tweet from authenticated User Timeline", I was able to call into the API with my username and password, and as the name implies, retrieve one tweet from my account (it turned out to be my last one).

I haven't looked at the source code, but, since the library takes a username and password to make the request, and I haven't registered my application, I'm assuming with good reason that this library uses basic authentication, at least for this example. As I said, during this dev phase, that's fine, but I'm going to have to revisit this eventually.

The code looks like this; yes, I took out my username and password. Notice I put this in a Command-based class (it implements the ICommand interface, typically "execute ( )"). So I'm using Commands in the Mate framework. Nice.


private var tweetr:Tweetr;
public function execute ( ) : void
{
tweetr = new Tweetr();

// set the browserAuth to false so we actually use
// the AIR authentication scheme
tweetr.browserAuth = false;

tweetr.username = "xxx";
tweetr.password = "yyy";

tweetr.addEventListener(TweetEvent.COMPLETE, handleTweetsLoaded);
tweetr.addEventListener(TweetEvent.FAILED, handleTweetsFail);

// tweetr.getUserTimeLine();
tweetr.getFollowers ( );
}

private function handleTweetsLoaded(event:TweetEvent):void
{
// assign the latest response to a data object
var tweet : StatusData = event.responseArray [ 0 ] as StatusData;

// trace some data
trace ( tweet.user.profileImageUrl );
trace ( tweet.user.screenName, tweet.text, TweetUtil.returnTweetAge ( tweet.createdAt ) );
}

private function handleTweetsFail(event:TweetEvent):void
{
trace ( "TWITTER ERROR ARGH ", event.info );
}


So far so good; I've found a library that lets me proceed with my development, like creating user interfaces for posting tweets, managing friends and favorites, and so on. I'm using Basic Authentication for now, but I know I need to change it, and since I've done Facebook application development already, I shouldn't have any problem tracking down resources and libraries to get me through this on the Twitter side.

Next, retrieving my own timeline, and creating a view for it, such that I can toggle back 'n forth between the public timeline and my own.

As always, thanks for visiting.

Labels: , , , , , , , , , , ,

Monday, June 1, 2009

Flash Flex on the iPhone? Setting up the Amazon Cloud Instance running Citrix XenApps

This is a continuation to my series of articles detailing how to get Flash Apps running on an iPhone...sort of. You really don't run Flash on the iPhone, you run it on a Citrix XenApps server, which runs on a Windows instance in the Amazon EC2 cloud.

My previous blog articles can be found here:

- Flash, Flex...on your iPhone?
- Monday, May 18, 2009 The Citrix Receiver Follow Up: Flash/Flex (and then some) on your iPhone...or Symbian...or WinMo...or...

Quick blurbs on what the technologies I mention above are:

- Flash/Flex/Air: if you're reading this article, no explanation needed.
- Citrix, simply, specializes in terminal-based delivery of applications. Think "thin client" delivery of applications.
- XenApps, in there own words, "Citrix XenApp virtualizes an individual application, be it Microsoft Office, PowerPoint, Excel, or SAP (sic, or Flash, etc.), allowing users to run those applications on a client directly from a XenApp server hosted with a Windows application."
- Amazon EC2, cloud-based computing infrastructure. I describe this more below.

So, my goal is to "Deliver Flash/Flex/Air apps, initially for the iPhone but eventually for any client, from the EC2 cloud running an instance of a Windows Server running Citrix' XenApps".

Whew. I could probably land a contract just by saying I know what that means.

In order to get this rolling, I'll have to get a Citrix XenApps instance running in the on the Amazon EC2 cloud. Citrix offers a video showing how to do this, you can view it here.

Three IMPORTANT notes, this is fair warning, and this is coming from somebody that has worked with resources in clouds before (I've just never been responsible for actually configuring and maintaining one).

- WATCH THE WHOLE VIDEO CAREFULLY. Believe me, you won't figure it out on your own if you've never done anything like this before.
- DO NOT SKIP THE VIDEO IN FAVOR OF THE "STEP BY STEP" IMAGES BELOW THE VIDEO. They don't provide enough detail.
- DO NOT USE SAFARI. If you're a Mac user, you probably know Safari doesn't always work well in sites that have multiple form submissions. The Amazon web pages broke quite a bit until I switched to Firefox.

Let's talk about what "an instance in the EC2 cloud" means. An "instance", is conceptually like a dedicated server...but it's not. It's an allocation of resources that appears to me to be a server, but which is disposable; when you terminate an instance, it's configuration is saved so you can restart it, but otherwise, the resources are freed up. The company, like Amazon, uses commodity hardware to build a platform to make instances available, and you pay for the time that each of your instances runs, because you're using resources in their cloud. When I terminate the instance, I don't get billed anymore, because there's no server to keep up and running, just a stored configuration that gets reconstituted into an instance if and when I start it back up.

Conceptually, the "cloud" is like a big ball of clay. When I need a chunk of clay, I grab off as big a handful as I need; I pay for that chunk based on the size of it, and how long I keep it out of the main big ball. When I'm done, I take a snapshot of the chunk, and just put it back onto the big ball. It's now available for anybody else to use, and my billing stops until I grab a new chunk, which by using my snapshot, can get instantly reshaped to the last known configuration. I can grab as many chunks as I need, shape them all differently, and so on.

It's a great model. In addition to a website hosted by Brinkster (where my blog and main site is), I currently pay almost $150 a month for a dedicated Windows server that I use for deployment and testing of customer apps. I pay for it whether or not I'm actually doing anything with it, which has irked me more than once. It's a business write off and all that, and IMHO an essential tool for any independent web-based software developer, but still, if I can economize by just using cloud instances of windows and linux servers, activating and deactivating them when I actually need them, and enjoy the easy flexibility of multiple environments (this one runs Tomcat on Linux...this one .Net on Windows Server 2008, etc.) I can cut that cost to a fraction and save myself multiple webserver config headaches and such.

Anyway, to get started, you go to the Amazon Elastic Compute Cloud EC2 Site. Initially, this is a little scary, because you see a list of usage fees by the hour, and you have to submit a credit card. But I'm intrepid, and have a business credit card, so on I go. I needed to set up an EC2 account, which lets me run select all kinds of pre-made server images that I can run as instances, and an Amazon S3 account, which is the storage mechanism for my files and so forth. They run independently of one another; again, remember that you're not actually running a server, you're running an allocation of resources, broken down into processing and storage. This way, I can run the same image as multiple instances, each with different (or differently configured) apps, using different amounts of processing power, all pointed at the same storage, or different areas of storage. Very flexible and elegant.

Anyway, the EC2 account I want to run my server images in is "$0.125 per Small Windows Instance (m1.small) instance-hour (or partial hour)". According to the documentation, it breaks down like this:

- You're paying by the hour, 12.5 cents, for every hour your instance is running. Hmm...let's assume I'll leave it up all day for a month: 12.5 x 24 = 300 cents = three bucks a day, x 30 = 90 bucks a month. I don't mind that as an investment in learning this technology and proving its use; if I land one contract because of this, it'll more than repay me in a couple of hours. And if course, I don't have to run it all the time.

- The specs for a Small Windows Instance, which should be plenty for my development experiments and demos: 1.7 GB of memory, 1 EC2 Compute Unit (1 virtual core with 1 EC2 Compute Unit), 160 GB of instance storage, 32-bit platform. Hmmm...we'll have to see how it goes. The large instance has 7.5 GB or memory, but is fifty cents an hour. So, here's hoping the Small Windows Instance can swing it.

So, you fill out the forms (again, don't use Safari), which when complete, takes me to a page with the following message:

"Thank you for signing up for Amazon Elastic Compute Cloud. We will e-mail you a confirmation when the web services are available for you to use. In order to begin using this service, you will need a X.509 certificate. You can Create a New X.509 Certificate or Upload Your X.509 Certificate."

Ok...so let's create the X.509 Certificate. If you don't know what one is, an X.509 certificate binds a name to a public key value; more generally, a public-key certificate is a digitally signed statement from one entity, saying that the public key (and some other information) of another entity has some specific value. So, by using a certificate, a browser and an application know that they are speaking to the intended targets by comparing those values; if it checks out, the communication is coming and going from where it's supposed to.

After a minute or so to create the certificate, I now have a certificate assoicated with my EC2 account, and my instances will be run using it.

That really seemed to be about all there was to it; strangely enough, by signing up for EC2, I seemed to have already signed up for S3; I went to the S3 page to sign up, but it told me I already had access, and as far as I know, I've never signed up for it before. It makes sense, but seemed a little implicit; I'd prefer to have at least received an explicit notice of some kind. It doesn't seem to cost me any additional money though.

Once that's done, you go to the EC2 Console and look up an image of the XenApps demo image. This image is located in the Community AMIs list after you click "Launch Instances" (search for "XenApps"). In order to do so, you'll need to create a security group and a key under which to run the instance; these items do things like open ports so that you can access the instance however you need, like HTTP, RDP, and via the Citrix clients. WATCH THE VIDEO, it explains exactly how to do this and what it means.

All in all, not so bad to get this end of it up and running. I still need to know how to upload and configure apps to make them available, but that's the next step. For now, I'm an independent developer with direct experience in setting up custom configured server instances in a cloud. I understand the benefit of it and can put out a wide number of configurations for any kind of client to access and test applications, and it's costing me twelve-and-a-half cents an hour to play with. Worth every penny IMHO.

Next, making Flash/Flex/Air apps available on my fancy new server instance running XenApps.

As always, thanks for visiting.

Labels: , , , , , , , , , , ,

Friday, May 29, 2009

"Buffering Video..." takes a hit: Akamai offers Flash Media Server 3.5 Dynamic Streaming

Akamai has recently announced support for Flash Media Server (FMS) 3.5 dynamic streaming; for the video developer muggle, this basically means that while watching a video, if your connection degrades, the player, coupled with the backend intelligence, can switch you to a lower bitrate video transparently. Although a lower quality video, the viewing experience will be interrupted considerably less--ideally, not at all--by buffering.

You can read the announcement here.

You can also see it in action at streamflashhd.com. If you have a decent connection, you can watch videos encoded at bandwidths from 500Mbit to 3000Mbit, and the quality will toggle as bandwidth fluctuations happen. If you have a bandwidth throttler, Charles, Fiddler, whatever, this can be an interesting thing to check out.

This is an opportunity for the higher end Flash developer type to differentiate him/herself from the rest of the pack, which is oh-so-important in the indie software developer world. Read on...

My clients are primarily in the entertainment and media industry; I build widgets, sites, applications, whatever they need. Frequently, this means dealing with video, and if you deal with video on an industrial level, you will sooner or later (probably sooner) run into Akamai.

I don't mind it at all. Akamai has a developer kit that makes it pretty easy to hook into their streams, with passwords, bandwidth detection, whatever (in fact, in their developer sdk there is a class, HTTPBandwidthEstimate, which is a generally useful utility). You can find more out about how Akamai helps Flash developers get up and running with their technology at their Flash developer page.

Anyway, just knowing that--and being able to prove it--has landed me work. But now, Akamai offers more.

Video delivery has become a lot more sophisticated in a very short period of time. Even just two or three years ago, it was enough to serve a catalog of video in a generic player as long as it was relatively stable; all the things we see now, like seeking in on-demand video streams, ways to interact with the player, HD video over the web, and all that, were generally avoided because it was VERY difficult to get right; users didn't have the bandwidth or patience for the buffering, complex video infrastructures are difficult to implement; a video player that does nothing but break when you touch it is just frustrating, and so on (and how many of those have we seen). Nowadays, users want more; ways to interact with video, like commenting and clip sharing, and of course, a smooth, uninterrupted, and easily seekable, experience.

Akamai has always been out there though, working to make enterprise-level video serving less of a headache. The principle is pretty simple. You are not a video delivery company. We are. Pay us to house and expose your video, use our services, feeds, and developer kits, to make them available to the public. Or, try and do it by uploading all your video to in-house web servers, you tube, whatever. That may work for a small effort, but if you have a lot of content and need it monitored, maintained, looked after every day...good luck.

That's not to say Akamai is without its issues; I've heard grumbling about their downloader, and network outages have made many a corporate manager sweat all over their cel phone. Say what you want though, they've survived and grown in the industry, and like I said before, the heavy hitters use them liberally. Whatever they're doing, there's enough value for people to want them to keep doing it.

As an entertainment/media focused developer (which so many Adobe-based developers are), having worked with Akamai is a powerful resume item. Frequently, if you hear "video" in a contract, you can expect it to be followed by something like BrightCove or Akamai. So like I said before, if you have experience dealing with these video hosts, you've got a leg up.

Now, if you have that background, AND know how to take advantage of Flash Media Server's dynamic stream switching, you're at the top of the industry. FMS 3.5, as far as I know, was announced in November, so there's been opportunity to get your feet wet for about half a year. You can read about the release of FMS 3.5 here (note that the current version is 3.5.2, which is a maintenance update):

So Flash devs, get to the Adobe FMS and Akamai sites, and start gearing up; time to break out of the world of banner ads.

As always, thanks for visiting.

Labels: , , , , , ,

Thursday, May 28, 2009

TcozTwitter: A Twitter Client using Adobe Air and the Flex Mate Framework - Day 2

This is a continuation of TcozTwitter: A Twitter Client using Adobe Air and the Flex Mate Framework - Day 1, in which I decided to complete a number of technical exercises by building a Twitter desktop client using the Twitter API, Adobe Air and the Mate Framework. 

If you recall, last time I was able to successfully make a call to the Twitter public data feed that returns the last 20 public tweets, and display them in a list in my client. It looked like this:




So, clearly I've got a ways to go, but certainly this represents a major element of the development; get the data, parse it, bind it to a list with the UI elements to properly display the data. Keep reading; the app doesn't look like this anymore.

The next step was to clean up the UI a bit, which is what we'll look at here. Although not a programmer as far as I know, iJustine, an internet/lifestyle tweeter and blogger of some notoriety, unknowingly gave me a suggestion for how to proceed. She said that she couldn't change the background color of her tweet display; I assume that if she wanted this feature, it would probably be a popular one, so I decided to implement a way to skin my Twitter client at a rudimentary level. 

And I must say, Mate made it pretty easy to do. I think any framework would have, being as the task of reading in config data is the same as reading in any other kind of XML data, and I had already set up a call/receive pipe for the public tweet XML, so ideally I should just be able to use the same exact technique, and that's exactly how it panned out. 

In the last article, I showed the fragment of Mate code (which is just MXML) that retrieved the public tweet feed. The code below does the same exact thing, except it hits a relative file, config.xml, instead of a remote service. 

The Mate formula for hitting data and storing it seems to be this:

- Create your Event class (in this case, Event_Config). This is a standard Flex/Flash event, nothing fancy. It should have a static constant (at least one, though it can have several) with the name/type of event you want to dispatch (which is always a best practice for events not matter what environment you're in). 
- Create a Manager class that will be passed arguments when the event is handled by the EventMap. This means creating at least one public method on the class. Interesting that none of the examples I have seen ever suggest exposing these public methods via an interface...which is something I'll comment on later. I used Manager_Config.
- Create a Model class, I like to use singletons, to hold the elements the Manager parses out.
- Tie the Event, and it's handler, to the Manager, via the EventMap. 
- Dispatch your event as needed, remembering that in Mate, events have to bubble to the EventMap, which initially, will be located in the top-level MXML file. This means that you can either only dispatch from an object that participates in the app-level DisplayList, or by using the GlobalEventDispatcher workaround detailed in my last article. 

The code fragment that does the above looks like this:



<mate:EventHandlers type="{Event_Config.GET_CONFIG}" debug="true">
<mate:HTTPServiceInvoker url="xml/config.xml" resultFormat="xml">
<mate:resultHandlers>
<mate:MethodInvoker generator="{Manager_Config}" method="storeConfig" arguments="{resultObject}" />
</mate:resultHandlers>
</mate:HTTPServiceInvoker>
</mate:EventHandlers>



So, when the app starts, I want to load the config.xml file, which I do like this:

- In creationComplete of TcozTwitter_AIR, I dispatch an instance of Event_Config, using type Event_Config.GET_CONFIG. 
- This bubbles to the EventMap handler MXML tag, which makes the call to the HTTPService, receives the result, and directs it to the Manager_Config class public method, storeConfigOptions.
- That method takes the result argument, parses the XML, stores the elements on the associated properties in Model_Config, which exposes them for use throughout the app. 
- At the appropriate times, the UI elements, like Tweet backgrounds, apply their colors as style elements. 

iJustine, there ya go. Again, more or less the same exact idea as grabbing tweets, or any data it would seem. 

Some observations on this flow:

This is the way the tutorials, and even more advanced samples I've seen, prescribe retrieving service data. Typically though, I would not use the HTTPService MXML tag (or any such MXML based mechanism for that matter), I'd forward the handling to a class using the Command pattern. I've read some ways to do this in Mate, but it seems that it's not the common practice; using the EventMap handler as the Command, and distributing the management of the result to Managers, is the norm. For basic things, this might be ok, but what if you have a complex command of some kind that runs several service calls? The MXML could get very bulky, or you'd need multiple handlers, which would seem to make atomic operations difficult to manage. In fact, I think that in an app of any size, EventMaps could get bulky fast, which would cause you to start thinking of your app in terms of layers of EventMaps. Conceptually, perhaps this isn't that much different than thinking of your app in terms of layers of Mediators in PureMVC, but plain old code looks a lot leaner 'n meaner to me than all those MXML carats, quotes, equal signs, and so on. 

Based on that, I'll probably only use an EventMap handler tag to initiate a command, like calling a service, if there is only ONE simple command and result. Anything more and I will broker it to a Command class, which fortunately, I know how to make dispatch events now (same as any non-view class, use GlobalEventDispatcher). I know Managers could be thought of as Commands, but they're really not, see below. 

Another observation which I touched on before; use of MXML tags instead of instances of classes lets developers avoid thinking of factoring their class hierarchies and exposing their public members using interfaces. I understand that the classes that back the MXML tags are well factored in this manner, but for example, in PureMVC, part of it is implementing the Command pattern as the "C" in "MVC" (control). As you may know if you've gotten this far, the Command pattern uses an interface to expose "execute". If you use a Template pattern (so you create a base class that implements the interface and you extend that base class whenever you create a specific kind of command), you've just made all your commands polymorphic, which lends to things like "undo", command stacks and chaining, etc. Mate doesn't seem to have this concept built in. 

Good thing, bad thing? I don't know. To me, one of the points of a framework is to prescribe patterns of development for common application tasks, like executing logic. If you use Cairngorm or PureMVC, all I need to know is that a developer understands the framework, and I know that when I say "call a service, handle the data, store it", that the developer--in the case of PureMVC--will dispatch an event to a Mediator, which will send a Command Notification to the Facade, which will execute the a Command class, which will make the service call and handle the result, then broker that result to to a Proxy class, which will parse the data and store it on the Model, which makes it available to the application. 

It may sound verbose, but it's explicit and actually saves a lot of time; I KNOW how the developer will perform the task, and if you're managing a bunch of them, that's a GREAT thing. Using Mate, it would seem that I'd have to lay out the flows myself and communicate them to the team as standards, and make sure they were doing it. With a team of PureMVC junkies, we may quibble about the best way to cut up an application with mediators, or the best way to represent a Model via a Proxy, but otherwise things like views calling views or views talking directly to models will never happen; if it does, the fix is to educate the developer on the prescribed mechanisms of the framework. 

Anyway, enough of that. The bottom line is, you make edits to an XML file, restart your app, and voila, there are your colors, nice gradients and all that. Note that an XML file is not how I intend to keep this; settings is a great opportunity to take advantage of Adobe Air local storage. But for now, until I establish a base set of requirements for preferences and settings, it's easiest to just keep it in something abstract and lightweight, as opposed to building out the settings UI now, knowing that it will just change drastically several times before I have a locked feature set. 

One other thing I took advantage of: Air's ability to have the app resize like a desktop app, and reflow the layout. This is a great thing IMHO; if you resize the Twitter HTML page, the tweets don't reflow to take up the entire width, they stay in one column. My client reflows the tweets to take advantage of the entire space, letting you see more tweets without scrolling. 

Next step: incorporating the metadata associated with a user, and getting that message field populated. 

Screenshots of the latest client below, showing the application of the config.xml, and the resize-reflow. As always, thanks for visiting.







Labels: , , , , , , ,