Thursday, December 17, 2009

Flash Builder: Spark Skinning Issue to look out for (hopefully they'll fix this)

If you're in the ActionScript world and haven't cracked open the beta of Flash Builder (the latest version of Flex Builder, just rebranded), it's time to hit the Adobe site and pull it down. There's a lot to like about it.


It ain't perfect yet though. Here's a brief post about a couple of things I've discovered that might throw you when you get started.


Spark Skinning

The new Spark components (get ready for the new s: namespace) seem to work great, and have a lot less overhead than the old mx flex ones. For instance, "groups", like s:HGroup and s:VGroup, can be used instead of "boxes", like HBox and VBox. They work the same way, but don't contain logic for scrollbars and such. This somewhat mediates the old Flex issue of nested containers impacting performance. Although you should still always be careful nesting containers, its good to know that, at least to a point, you can be a little more creative about their use without overtly damaging your app's perf. You can also do more with CSS than in the past as far as skinning, fonts, and so forth. Great stuff.


However, it's still in beta, and I stumbled across what appears to be more of an API/OOP design flaw than a bug, but nevertheless still feels like something is broken, so here it is:


When using a Spark List component, you may want to reskin the Scrollbar (let's face it, the default scrollbars are UGLY). To skin the scrollbar, you would implement a new skin class for the part of the scrollbar that you want to alter, then simply apply it to that element of the scrollbar. The easiest way to to this would be to just copy the content of the default skin class, put it in a new class, modify it to suit your needs, then apply it in place of the default one. Note that the Spark documentation says this is the way to go; you shouldn't override or extend skin classes.


However, the default scrollbar skin for the increment and decrement arrows contains an "Arrow" MXML piece. Remember, this is the SKIN class, not the implementation class. Even if I omit the skin class entirely, I would expect the app to still compile and run; a null check would avoid any errors, though you may not see a skin for the scrollbar, or a default system skin would be used; something other than the app completely breaking without any compile-time errors.


You can find the Spark skin classes in [FB Install folder]/sdks/[version]/frameworks/projects/sparkskins/src/mx/skins/spark, which is great; using them as a starting point for skinning you Spark components makes this actually very easy.


Anyway, in those default Arrow classes (the ones I'm interested in are ScrollBarUpButtonSkin, and ScrollBarDownButtonSkin), you'll see this MXML fragment:



<!-- arrow -->
<s:Path horizontalCenter="0" verticalCenter="-1" id="arrow"
data="M 3.5 0.0 L 7.0 7.0 L 0.0 7.0 L 3.5 0.0">
<s:fill>
<s:RadialGradient rotation="90" focalPointRatio="1">
<s:GradientEntry id="arrowFill1" color="0" alpha="0.65" />
<s:GradientEntry id="arrowFill2" color="0" alpha="0.8" />
</s:RadialGradient>
</s:fill>
</s:Path>


Now, I don't want that, because I'm drawing some very custom shape in place of this default arrow. So, I omit that MXML fragment, and replace it with a Graphic object, in which I use the new drawing MXML stuff to create a new arrow.



<s:Graphic width="25" height="20">
<s:Path data="M 0 0
L 25 0
L 25 10
L 12.5 20
L 0 10
L 0 0" >

<s:stroke>
<s:SolidColorStroke color="0x29a094"/>
</s:stroke>

<s:fill>
<s:LinearGradient rotation="90">
<s:GradientEntry color="0xFFFFFF" alpha="1"/>
<s:GradientEntry color="0x7ac8c5" alpha="1"/>
</s:LinearGradient>
</s:fill>

</s:Path>
</s:Graphic>


After making the new class with the Graphic element instead of the old "arrow" drawing path one, I applied it to my Spark List component and compiled; new errors. I ran the program though, and it crashed right away. The error was that the "arrow" property could not be found, and there was no default value, etc. So, out of curiosity (and the desire to get the app running), I just added a public var, "arrow" : Object, and again compiled without errors. Running it though caused another error, and then another, because "arrowFill1" and "arrowFill2" were not found, no default value, etc.


So, I had to add these three public vars to my custom class to get the app to run.



// don't remove these, they are placeholders for the wonky "arrow" mxml that isn't needed here.
public var arrow : Object = { };
public var arrowFill1 : uint = 0;
public var arrowFill2 : uint = 0;


After that it worked.


To me, this is broken; as long as the skin class is properly made, it shouldn't need to contain ANYTHING in order to run properly, as long as any necessary interfaces are implemented (a well built API should be interface based). Implementation of functional objects should not be a concern of the skin class. But it is; you have to put in those dummy properties to get this to work.


I circulated this find, and the consensus seemed to be that yes, this should be fixed; there's no reason a required visual object should be in a skin class, circumventing compile time errors and crashing the entire app when it tries to instantiate a skin for a scrollbar. Evidently, more hacking away found that this is the case in a number of Spark skins.


Insurmountable? Nah, just add the public properties to satisfy the Spark parent component demand for whatever it's looking for. But it's wonky and, as far as the consensus of the people I referred the error to, should be addressed by Adobe before the product is released, for the sake of elegance if nothing else.


As always, thanks for visiting.

Wednesday, September 9, 2009

Put an image (or whatever) next to any character in a TextField that wraps and is multiline.

Somebody on the Adobe AZFPUG (Arizona Flex Programmer's User Group) asked today, "I have a TextField that is multiline, and has numerous wrapped lines. I want to be able to put an image RIGHT NEXT to the last character. How?"

Most of the responses were along the lines of "get the x loc of the textfield, and get the width, then get the y loc, and the height, then put the image".

That'll always put it to the lower left of the TextField. It won't put it next to the last (or any) character within the TextField.

I've dealt with this before, and was surprised to see that this person was really having a hard time finding a solution. So I gave her one: Here it is.

If you're not familiar with getCharBoundary ( indexOfChar ), look it up. It can save your life. It returns a rectangle that bounds any character you specify in a text field. A rectangle has an x, y, width, height. So you get the rectangle, do the math as below, and voila...place your display object.


private function doIt ( ) : void
{
// can be anything, movieclip, combobox, image, whatever
var img : Image = new Image ( );
img.source = "timprofile.jpg";

addChild ( img );

_txt = new TextField ( );
_txt.x = 100;
_txt.y = 100;
_txt.multiline = true;
_txt.wordWrap = true;
_txt.width = 200;
_txt.height = 200;
_txt.text = "Hello how are you I am fine ok that's very nice thank you ok let's wrap some text I hope this wraps let's wrap it up nice ok";

rawChildren.addChild ( _txt );

var r : Rectangle = _txt.getCharBoundaries ( _txt.text.length - 1 );

img.x = _txt.x + r.x + r.width;
img.y = _txt.y + r.y;

}


As always, thanks for visiting.

Tuesday, August 11, 2009

(To Unix guy) Yes, it does...Windows Has Symlinks.

This is one really started to irk me lately, so here we go.

Qualifier: I am not a Windows fanboi at all. My primary machines are Macs, with a Windows box for Windows-only games and testing, and a remote one for development (I have two, one Centos, the other Windows Server). However, I am not a Mac fanboi either. The primary reason I own Macs is that in my field, most people work on Macs. Mac is also ruling the roost of UI-think these days, and I'm a UI developer. If and when the wheel turns, depending on the wants and needs of my clients, I will too. The ability to reinvent yourself is what keeps you viable and current; just ask David Bowie or Will I Am.

That said, to all the Unix guys who wave symlinks in the face of the Windows developer:

WINDOWS HAS SYMLINKS. YES IT DOES. THEY ARE CALLED NTFS JUNCTIONS.

I post this because recently, a friend who runs a business got shafted by some PHP developer, who got in over his head, screwed up his site, and suddenly "wasn't available". He got the entire site zipped up and sent it to me. It didn't work when I just dumped it into XAMPP on a Windows dev box I have running; the pages were requesting directories that didn't exist in the file structure I was sent.

I contacted him, and he responded, "what are you running it on", I said, "oh, a Windows box". He said, "you can't do that, the site uses symlinks".

While I understand the "why" of why he did this (easily point at other directories to try other versions), I don't really think it's in the interests of the client (and therefore, isn't a good idea). You can just rename directories to try alternate versions of a codebase. It also defeats the purpose of the whole "can run on anything" mantra; as far as this developer knew, he had tied a basic PHP site to Unix-based OSs, with the thought that, "you shouldn't run Windows". My friend (the business owner) had no knowledge of this decision whatsoever, as far as he knew, PHP ran anywhere, mySQL ran anywhere, the site was portable.

So here's a pro note: don't tie your websites to a particular platform unless you have to, and inform your client if you do, that "you will not be able to move this to Windows", or ".Net is, in practical terms, Windows technology. Your site will not be directly portable, if at all, to Unix/Linux".

Anyway, I responded, "that doesn't matter, Windows has symlinks".

He responded, and I have heard this from people at a particular startup I did some work for not long ago, who considered themselves superior to anybody that touched a Windows machine, "Windows doesn't have symlinks".

And like I said then:

YES IT DOES. THEY ARE CALLED NTFS JUNCTIONS.

So, either get the Windows Server Resource Kit to get the "linkd" tool, or just get the small, free Junction tool that's been around for a few years. If you have either of them though, it's a breeze.

With Junction (which is what I use), it's as easy as:

- Create an empty directory (your "symlink").
- junction c:\path\simlinkname c:\path\actualdirectory.

That's it. There's also commands to inspect directories for symlinks, delete them, and so on.

Note that, as far as I know, symlinks to directories on remote shares are not supported by Windows. This may not be true on the newer server versions, I dunno.

Here's a list to Junction (which I use now instead of moving around the whole Windows Server Resource Kit, which you can look up if you're so inclined):

http://technet.microsoft.com/en-us/sysinternals/bb896768.aspx

Happy Windows symlinking!

Thursday, July 30, 2009

Flex: Masking Images using other remotely loaded images

I had to do this recently, due to their being a very large number of images in the project I'm working on, which needed the backgrounds knocked out; it was easy to generate the masks in an automated way, it was not easy to alter the images to alpha out the backgrounds.

In Flex, they say one display object can work as a mask for another. This is true of course, but for dual remotely loaded images, properly making sure the images are entirely loaded via load.complete events, and so forth, is the key.

The following little technique shows this, code snippet below. This is proving to be quite a timesaver for the team as a whole, since the graphics guys don't have to worry about altering their entire catalog of images. I've already recommended that a back-end process should generate AND apply the masks so that Flash doesn't have to make 2x the requests for images (every image needs a mask): from a performance standpoint this is a bit of a nightmare, but, it's a solution that is moving the project forward and is easy enough on my end to implement.

Note that the images I'm using for masks are not the standard black/white masks you use in photoshop. They are PNG-8s, with everything BUT the shape you want to see alpha'd out, with 8 colors, not converted to sRGB, no metadata, etc. A roughly 400x400 image mask comes in at around 2kb with this profile.

I'm aware this isn't exactly new, and it's documented, but it's solving such a significant problem I figured I'd make it visible. I actually use this code snippet in an itemrenderer, so that I can just chuck an array of objects at a tilelist, and have the item renderer do the two-step loading.

Notice also:

- I'm combining pngs and jpgs, it doesn't matter it's all rendered as bitmaps by the client in the end anyway.
- I'm using a two-step loading chain; it seems you don't have to do this necessarily, but every now and then, it seems to fail if you don't. The two step ensures the mask is ready to go before the image every time.

import mx.controls.Image;
import mx.events.FlexEvent;

private var _mask : Image;
private function onCreationComplete ( event : FlexEvent ) : void
{
_mask = new Image ( );
_mask.cacheAsBitmap = true;
_mask.addEventListener ( Event.COMPLETE, onMaskLoadComplete );
_mask.load ( "images/testmasks/picturemask.png" );
}

private var _img : Image;
private function onMaskLoadComplete ( event : Event ) : void
{
_img = new Image ( );
_img.cacheAsBitmap = true;
_img.addEventListener ( Event.COMPLETE, onImageLoadComplete );
_img.load ( "images/testmasks/picture.jpg" );
}

private function onImageLoadComplete ( event : Event ) : void
{
addChild ( _img );
addChild ( _mask );
_img.mask = _mask;
}


As always, thanks for visiting.

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

Friday, June 19, 2009

iPhone 3G S Unboxed, and some immediate things I noticed...

Here it is, in all it's shiny new glory. Time to upgrade from the OG (though I will keep it on as a developer device...it's still a perfectly good phone).

Some immediate things:

- Looks like WiFi settings don't roll over on a fully sync, I had to dig up two of my old wifi keys.
- Compass looks like it's subject to interference. I had it near a monitor and a wireless mouse, aside from that I can't see any powerful magnets or wireless devices that would cause undue interference.
- The home button doesn't "click" anymore, you just touch it. EDIT wrong...it was just sticky. It clicks.
- Initially, the Tekkeon "MyPower" battery/sleeve I bought, which worked fine with the iPhone OG and says it works for the 3GS on their website, reports "charging is not supported with this accessory" on the 3GS. Not good.
- The restore went VERY quickly; the 8mb from my OG iphone was done in about five minutes.
- It doesn't come with a little dock.
- The OG docks doesn't seem to fit.

Compass Fail:





Tekkeon Fail:





iPhone Unbox:




























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.

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.

Thursday, June 11, 2009

Flash Catalyst: Why I'm not so sure this is a good idea.

If you read this blog, you know I'm a Flash/Flex/Air type developer. I've been working with these technologies in one form or another since ActionScript was called Lingo, and I know where the FS in FSCommand comes from.

To make my point early on, I am having serious reservations about Catalyst. I saw a live presentation from Adobe yesterday introducing the Catalyst beta, in which I feel the presenter sidestepped my questions regarding how Catalyst was actually a step back, not forward. I've downloaded and played around with the tool, and while I think it's a remarkable GUI authoring environment, I believe that it is going to reintroduce a variety of workflow and stability problems that were finally getting solved with Flex.

Catalyst, which is marketed as, "Adobe® Flash® Catalyst™ is a new professional interaction design tool for rapidly creating user interfaces without coding.", is detailed at the Adobe Catalyst Beta web site.

Now the discourse:

As an independent, I've worked on teams of all kinds, every shape and size, in a variety of different business verticals: entertainment, media, financial, you name it. After a while, you get a notion of what works, and what doesn't. When I get pinged about a project, I've gotten pretty good at anticipating what I'm getting into based on the project description, who was involved before, and what the current state is.

One of my biggest nightmares in the ActionScript world is getting involved in a project where, "the code is already written, we just need some changes and fixes to be made." Naturally, I always respond with, "why can't the original developer do it?" The usual reply, "oh he's not available." This may be the whole project, or just a piece of it, but the result is the same.

I've come to know, that almost without variation, this actually means:

"We had some great visual concepts for this application we wanted. We interviewed a number of developers that talked about things like wireframes, functionality, and specs. It seemed complicated and time consuming, we wanted immediate gratification. We found a guy who had this great looking website, really good design, who said he knew Flash. So we hired him. It was going along great, really fast, but when we requested some new features, and changes to old ones, and integration of some new data, the developer turned out to be unavailable."

I have visions of this designer, who at best may have understood a handful of canned script procedures, furiously googling ActionScript samples, hunting down code scattered all over named timeline frames, looking at a library of unnamed assets that was allowed to get out of control, posting "can anybody help me" on the boards...

...and now the client wants an "expert" (vis a vis, "somebody else to share the blame") to come in and clean it all up. No documentation, no access to the developer, or at best a hasty email saying "it's all on frame 2 just look at the code", missing external assets, often not even a project that will compile.

This isn't a once-in-a-while scenario. I see it ALL the time. When I was making my bones as a contractor, I'd take these jobs. Now I avoid them like the plague, because they're losers. Why? Because the client will feel that because it used to work, or currently does but just not the way they want it to, it should be cheap and easy for an "expert" to get it running as required.

What they don't know is, the project is a disaster, there's virtually no unravelling it, and even if you can, huge portions of it will need to be rewritten anyway in order to get the extended features working properly...

...but, they cry, "Flash is a visual development environment. It's supposed to be easy to create interactive widgets. I don't understand why OOP, or documentation, needs to be involved with this at all. We're not looking for an application per se, we just want this little bit of video/playlist/data functionality, but instead of doing it this way, we need some changes. We need you to be flexible."

This is what happens when designers are put either in charge, or at the top of the process, of actually building software.

If you're a designer, you're probably insulted now. Stay with me, I think you'll see what I mean. If it helps to keep you reading, I have IMMENSE respect for a designer that understands how to work with a software developer. It's just that the overwhelming majority of "Flash" designer/developers don't, because they assume that coding is secondary to design. I know it for a fact.

If a coder makes comments about design, the designer will certainly not take it as authoritative. Why? Because a coder != designer. If you've taken it upon yourself to study both design and coding properly, more power to you. But in general, a coder may have some design ability, or a designer may have some coding ability, but the "some" is secondary, it's not a studied, practiced, primary skill.

Flash is not a design tool. I don't care what Adobe tells you, or what you've seen people do with the vector drawing tools. Flash is a tool used to build interactive, web-based software. Call them widgets, call them stand-alone components, call them "players", call it "a design-time scripting environment that builds interactive media", whatever. Those are euphemisms.

YOU ARE BUILDING SOFTWARE, and that ENTAILS SPECIFIC SKILLS.

No, Flash isn't for building operating systems. It doesn't have to be. An extension on the house for grandma, or a new hi-rise on the waterfront, are both "buildings" created through the process of "construction". You have to get permits, zoning, you need blueprints, good material, and a knowledgeable contractor with specific skills.

If you've ever watched BBC, there's a show called "How Not To Decorate". These two Brit designers ("the Lads") go into these nice homes that are atrociously decorated, and have them restructured to accommodate their design vision...THEN they add the design. I love this show because I see it as being directly analogous to software development. Do you see these guys selecting foundation materials, or trying to put cushions in the room before the builders say "ready"? Do you see them working without blueprints, only using their comps? Do you see them trying to find tools that build foundations without doing any digging?

No. You don't. They recognize their expertise, and work within the boundaries of their roles. They hire top-notch builders to explain to them what can and can't be done in terms of the design concept. They push the builders, but in the end, when the construction lead says say "not with this budget, not in this time, not in this space, not in this ground", they accept the limitation and rethink. They are integrated in the process, they attend the meetings when it makes sense, in fact, they are in charge. But they don't actually do the construction work. And in the end, they never get "pixel perfect" according to their original design vision; they work with the finished structure, rethink some of the concepts, and succeed. They don't say, "my comp shows this 10 inches this way. Tell the builders to tear down the wall and rebuild the room."

WHY does this basic, obvious, logical and sensible thinking, fall apart when it comes to Flash? There are so many bad examples to prove it, so many that Flash is easily maligned by all the "Web 2.0"--whatever that is--fanbois (apologies to Mr. O'Reilly) as being unstable and bulky garbage.

A few years ago, enter Flex. Adobe takes a stand: Flash development is about CODE, and that means, CODERS. I saw an Adobe presenter proclaim this vehemently in both the presentations I saw him give. The designers were up in arms; how dare you! I'm a designer, I don't want to have to learn about code. I want the tool to do it for me. You are ruining my livelihood!

No, we're not. We're simply giving you the opportunity to do what you do properly. Flex has a great workflow for this; finally, architects and coders were back to doing the construction. Designers were integrated where it made sense; they created assets based on areas of the project that are completed and stamped "ready" by the builders. They worked on the CSS and images in Photoshop and Illustrator, burned them up into vector images and/or swfs, or whatever, and placed them as static assets or libraries, ready to be applied to the finished components. It's a solid workflow.

The job boards are the evidence: enterprises are starving for Flex developers, because at last, it seems like we're getting some stable software out there. Flash isn't a toy after all, you just have to apply professional workflow, to any size project, to get it running. Architects and coders lead construction. Designers create vision and assets, which are integrated when the time is right. That's how you build things. Event "the Lads" know that.

Yesterday, the Adobe presenter said that Flex put code and development first, design second, and that they saw this is being "backwards"; the fix is Catalyst. Designers would once again be given a tool which, with very little or no code, they can use to take their designs FIRST, and THEN apply code, which is auto written.

He even went so far to say that the Flex developer can view the code, and edit it as necessary. Oh-my-gawd...say it isn't so. You are actually saying it's a good idea that I work with code whacked together by somebody that knows nothing other than how they want it to look, and maybe has a rough notion of how it should work? And that they should be doing this on their own in a completely different development tool?

Think of it this way: why doesn't Adobe create a tool that let's programmers auto-generate designs based on wireframe structures? Let us give designers .psd or .ai files with auto-generated and named layers, pre-sized assets, all the rest of it, and let them just clean it up as needed.

Why? Because it wouldn't work. Designers would shit all over it. And they'd be right to. But this is exactly what they did to developers with Flash, fixed with Flex, and are doing all over again with Catalyst. Designers are getting involved in more than design, they are now generating MXML...lots of it. And the Flex developer is going to have to deal with it.

I talked to two other experienced ActionScript coders, that work heavily with Flex, about this. They felt the same way; here we go again. Designers are going to throw stuff over the wall to us and we're just going to have to deal with it. If an event doesn't fire correctly, or a state change doesn't work, we're not going to be able to go back to the designer and say "rework the component". They'll say no, it's not their job. And the client, as usual, will side with the designer, because...designers aren't coders. That's your job, Mr. Flex OOP guy.

Adobe has caved; this is 180 degrees from what they were saying maybe three years or so ago. Once again, they're marketing immediate gratification via Catalyst. Designers will latch onto it because they can make text fields change color when a button is clicked, and the assets will look exactly how they want, but they won't really understand what the tool is generating, because Adobe is telling them not to worry about it, let the Flex guy sort that out.

With all that said, my predictions:

- Catalyst will flood the field, once again, with designers fronting themselves as developers, and when a serious ActionScript guy on the project says, "this stuff is useless, the designer needs to rework the component", everybody will say...no man, that's your job.
- I will end up using Catalyst, because I'll frequently tell a designer, "just send me the assets, I'll rebuild the component". So, Adobe's notion that designers will use Catalyst, developers Flex, is misguided. Exactly as I am frequently forced to crack open Flash to fix these things, so I will be forced to crack open Catalyst.

Can Catalyst be used productively? Sure, if a team discusses the tool with the designers and specifies how exactly it's to be used. Unfortunately, in the world of independent development, that rarely happens. Marketed and prescribed workflows are rarely adhered to in all but the most well-funded, tightly controlled, corporate projects. I've seen startups collapse and corporations throw away piles of money because of this, and I don't think it's entirely their fault. They're being misled into thinking that software development is a commodity skill that should be cheap and on-demand. Design, on the other hand...now that takes something special, that's an art.

Ugh. Once again I'm going to hear...

...we had this designer come in, he used Catalyst, so all the code is written. There's a few fixes though, and we need some changes made to extend the functionality...

...and once again, now that I don't need to deal with that BS anymore, I'll hang up.

Tuesday, June 9, 2009

Buying the iPhone 3GS: Existing customers, buying from either Apple or AT&T doesn't matter, and woe to the non-upgrade eligible!

Figured I would blog this to put an actual experience buying an iPhone 3GS, with details on upgrades and non-upgrade purchases. Not to mention that...I mean, c'mon. I gotta have a blog post about the new iPhone, and at this point, aside from what everybody already knows from the WWDC, this is all I've got to add.

I'll start with the bad news: if you're not eligible, this article from Boing Boing is the reality:

IPHONE 3G S: WORLD'S BEST PHONE SADDLED TO WORLD'S WORST CARRIER

The article states:

For non-qualified customers, including existing AT&T customers who want to upgrade from another phone or replace an iPhone 3G, the price with a new two-year agreement is $499 (8GB), $599 (16GB), or $699 (32GB). Visit www.wireless.att.com for eligibility information.

Lucky for me, this doesn't apply. I didn't see the upgrade to 3G to be worth it. True I was a little jealous of the network speed now and then and the maps feature on 3g worked better, but the overall ROI just didn't seem to be there. Funny the things people said; the CEO of a startup I did some work for said, "you must not be a power user". Erm...no. I'm just an adult that made a decision based on value.

Anyway, let's talk about upgrade purchase. I have an OG iPhone, have had it since day one. Yesterday I bought a 32gb 3GS iPhone from the Apple Store, right after I got the email following the WWDC, so it was about 6:30 p.m. EST. It cost $299, and the ordering process appeared aware of my current AT&T plan and upgrade eligibility, actually asking me if I wanted to upgrade any portion of it. I also paid for one-day shipping, which was $16 dollars. The total was $337.05 with tax, and the shipping date is June 19th. All this was sent to me in an order confirmation as well, so as far as I can tell, I'm good.

So, to clarify, because people have told me otherwise...THERE IS NO DIFFERENCE BUYING FROM THE APPLE STORE OR AT&T. NONE. The Apple store is aware of your upgrade options and so on, and AT&T customer service told me point blank that it doesn't matter.

Why didn't I buy from AT&T directly? Only because I got the offer email from the Apple Store first, and wanted to place me order ASAP.

Anyway, to nail in the facts, I went to the AT&T site, and checked out both "Add an new Line", and "Upgrade".

This picture was identical for both "add a new line" and "upgrade". Note it's $299.



A visit to the website, a call to customer service, and my email confirmations, confirmed it all. If you're reading this, you have the facts: eligible for an upgrade, the phone will cost you $299, not eligible, it'll cost you $699 for the high end. And there is no difference if you buy it from the Apple store or from AT&T.

I'll tell you this, for that money, I would just upgrade the 3G to the 3.0 OS and forget the new phone; wait for the next one. I just don't see it being worth the money, exactly as I didn't see the 3g being worth the money compared to the original, and, if you're already a 3g owner, you're on the faster network. I have a feeling that, aside from the better camera (which really still isn't all that great) and the bigger capacity for the high end one, there isn't much of a difference to the typical user.

What would NOT surprise me though, is if all of us upgraders get ROOKED six months from now, exactly as we did when the iPhone first released, the price plummeted later on, and they gave us a $100 rebate usable for in-Apple-store purchases (thanks Steve J. for the $87 power cord for my $3,200 first-day Macbook 17). Six months later they'll put out a faster network and another phone on it or some BS like that. Apple has a history of this and it sucks.

But then I'll just resign myself to another two years, and enjoy my new iPhone, exactly as I do my current one. I never lost a contract because I broke out a pre-3G.

There you have it. As always, thanks for visiting.

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.

Friday, June 5, 2009

Why Amazon EC2 is a great thing for the Indie developer. At least, that's what I'm finding.

I've been working with Amazon EC2 a lot lately. I'll tell ya, this is a great thing for independent developers.

For those of you that don't know, EC2 is Amazon's computing cloud, in which you can run instances of virtually any kind of computing environment for pennies an hour. It's all managed right through a web interface. Go to the Amazon Elastic Compute Cloud website and check it out.

As an independent, I work with different clients all the time. Some use Linux, some Unix, some Windows. That doesn't matter to me per se, because I generally work with technologies that have runtimes for most commercially viable platforms. But, in order to look more professional, I've taken it upon myself to provide clients with a staging server, as well as SVN and FTP repositories. You would be amazed at how many times a client has said to me, "you can do all the staging, AND will set us up with SVN accounts?". Yep, I'm serious about this business, and want to make it as easy as possible to integrate me into your workflow without the hassle of setting me up internal accounts and access for the piece I'm building.

The staging server is a Windows box. The reason for this choice: I can run .Net on it. People frequently ask me, "why do you bother with that," to which I offer canned response, "I'm not going to lose work because I have a religious belief about a given technology". If the client wants .Net web services to power the Flex UI, that's fine with me. If they want Java, or PHP, or Ruby, same thing. All of these technologies are fully available on Windows. The same is not the case with Unix or Linux. People guffaw at this, pointing to .Net implementations on the Unix base, but that's not what clients use. So, to run as many technologies as I can, Windows was the logical choice. I can drop a MAMP server on it for PHP/MySql, run Tomcat and Oracle Comm. Edition for Java, and power IIS with .Net and SQL Server, or any combination of the above, all at the same time.

It costs me money though, even when I'm not using it. About $150 a month to be precise. I host with Liquid Web, which I must say does a GREAT job. GREAT. Their support is on point, and I've never had an outage in more than two years. But fact is, I do most of my development locally, and just do a daily dump it on staging so the client can eyeball it, but otherwise, I store my SVN repos on their, do some experimentation with server products and whatnot, and that's about it. If I want to test on anything other than Windows though, I do it on local virtual machines, like a Parallels Centos VM or some such. Its been a great model for working with all kinds of clients, managing the environments is great experience of course, but...

...enter Elastic Compute Cloud. The concept is this: it's a big ball of clay. When I want a piece, I pull it off; this is my "instance". I can shape it any way I want, and only get billed for when it's active. When I'm done with it, I "bundle" it (essentially a saved configuration) and put the raw material back onto the big ball, which stops billing.

Billing, btw, for a "small instance", which is roughly equivalent to my $150/month hosted box, is 0.125 dollars/hour...that's twelve and a half cents and hour.

Amazon provides you with all kinds of pre-configured instances: Fedora running Ruby on Rails, LAMP, 64 bit versions, Windows Server 2003 and 2008, etc. Additionally, the "community", which is made up of all kinds of platform developers like Citrix and what not, provides Windows, Debian, Fedora, SUSE, Ubuntu, Solaris, Gentoo, etc. images of all kinds, running their databases, VM servers, and what have you. They also put out a lot of demo instances so you can check out new technologies and services...for FREE, all pre-config'd. No downloading, installation issues, and all that. True, it's important to know how something installs, but first, let me see if I'm interested in the technology before I fight with a download and install.





So, here's the scenario. I have a client that works entirely in Linux using MySQL, and they want to see the deployment of my product in that environment. Currently, I can't do it, because my box is Windows; I can certainly demo the product working and use MySQL, but it's not Linux. So, I send it to them and have them deploy it, but that detaches me from the process, which causes iterations. I need to see it running--or breaking--to fix it fast.

With EC2, I can just develop locally, test on a Linux VM, and when I'm ready, fire up a Linux instance in EC2 and deploy it. I make any necessary changes and fixes, and when I'm done, can show it to the client running in an environment similar to theirs, and be reasonably certain that if they deploy it correctly--and there's nothing exotic going on, and of course there's nothing I can do about their internal security boundaries--it'll work.

I start the instance when I need it, stop it when I don't. Even if I leave it running 24/7, it's ~90 a month, still sixty bucks cheaper than my current environment. I write it all off true, but it's not just about the money, it's about being able to come as close as possible to the deployment environment. It looks really pro and builds client confidence. "Wow...you have this running as an instance in a cloud? How did you set that up?" is a question I've already been asked.

And because it's cheap and timed, it's very easy to bill back to a client. I usually don't do this, preferring to just build it into my rate, but in this day and age of economizing, being able to draw out line items on an invoice is important. If a client declines, that's fine, but I make the point that for essentially pennies they are compromising my ability to ensure they are getting a working product in as few iterations as possible. I expect that my clients will say, "spend the fifty bucks".

Lastly...I'm an independent developer, and am getting a firm, hands-on grasp with cloud computing and how to use it effectively. That's the sort of experience that sets you apart from the typical "I do flash sites" kind of hacker.

There you have it. If you have the chops, being an indie dev isn't as hard as you'd think. I find it far more rewarding than a straight corporate job, and if you read my blog, you know I've had 'em. But to stay on top of it, when new tools or services come along that let you economize and work smarter, you gotta get involved. For me, EC2 is definitely in my toolbox.

As always, thanks for visiting.

Wednesday, June 3, 2009

iPhone app development...using JS and HTML instead of Objective C? Freakin' amazing!

I had to try this; check out NimbleKit. I dabble in iPhone development, and have already gone through the rigor of Objective C, but I mean...JS and HTML?

NimbleKit touts, "NimbleKit is the fastest way to create applications for iPhone and iPod touch.You don't need to know Objective-C or iPhone SDK. All you need is to know how to write an HTML page with Javascript code."

I'm dubious to say the least; write in one language, compile to another completely different environment, is something I've seen blow up more than once. But then again, I was dubious of the Google Web Toolkit, and that worked really well when I needed it. With that said, let's give it a try. I downloaded the installer, which adds a new project type to your XCode iPhone Applications project templates:



Firing it up brings you to the dev interface for the project. It looks more or less like a regular app, with the addition of a the NimbleKit supporting binaries, like libNimbleKit.a, the NKit.js library, and an HTML folder in the project explorer. The page of interest to me is located in that HTML folder, called main.html, and we see it includes the NKit.js file.



So, let's compile and run the project on the iPhone (I'm a registered developer) using just the default HTML text in the emulator...BONK! NimbleKit wants you to register NimbleKit, and initialize it with the serial number they send you in order to test on the iPhone. I'm not inclined to do that at this point but, it did show that NimbleKit will deploy the app to the iPhone without issue; I actually see the icon on the iPhone and everything exactly as you'd expect. The pic below is a screenshot from the iPhone:



So, for now we're using the emulator. My confidence is building though, if this thing really pans out I might just register and get a serial number. Right now though, there's very little documentation and only one tutorial. I think I'll wait for another rev to commit.

There's a tutorial showing how to build a simple "Radio" application, but what I think I'm going to do is just try to knockout a hello world that loads an image. Right off the bat, you can see that, while you use JS and HTML as your "MainView", which is what you put UI items on. Let's try to add a button, and an image control, so that when we click the button, the image loads. Nothing fancy, but this gets us through creating and positioning UI elements, hooking up events, and UI elements that react based on the result of that event (in this case, a button click). This is a basic exercise I try in any UI development environment I come across.

In Objective C, the code might look like this; this is the implementation class, I'll leave out the interfaces and whatnot. Note that in the NimbleKit project, I don't have to worry about the separate interface and implementation objects, I just work right on that HTML page directly.


- (void)loadView
{
[ super loadView ];

mainView = self;

btn = [ UIButton buttonWithType: UIButtonTypeRoundedRect ];
btn.frame = CGRectMake ( 110, 10, 100.0, 20.0 );
[ btn setTitle: @"Load Pic"
forState: UIControlStateNormal ];
[ btn addTarget: self action: @selector(btnClicked:) forControlEvents: ( UIControlEventTouchDown ) ];

[ self.view addSubview: btn ];
}

- (IBAction) btnClicked:(id)sender
{
/*
UIAlertView *alert = [ [UIAlertView alloc]
initWithTitle:@"Hello DevX" message:
@"iPhone, here I come!"
delegate:self cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil];
[alert show];
[alert release];
*/
img = [ UIImage imageNamed: @"cat.jpg" ];
CGSize imageSize = img.size;
myImageView = [ [ UIImageView alloc ] initWithImage: img ];
myImageView.frame = CGRectMake ( 0, 100, imageSize.width, imageSize.height );

[ mainView.view addSubview: myImageView ];
[ myImageView release ];

}


So, let's try and port that same idea into NimbleKit. Although there's no documentation, I saw in the video and in the screenshot on the home page that the UI elements are preceded with "NK". Those aren't native iPhone framework names...hmm, where do I get the object names? My guess would be, since you do this all in a JS script tag, I'd need to look in the nkit.js file, and sure enough, that's where I found what I was looking for; NKButton, and supporting methods.


function NKButton()
{
this.init = NKPlaceNativeButton;
this.show = NKShowNativeButton;
this.hide = NKHideNativeButton;
this.setTitle = NKSetNativeButtonTitle;
this.setImage = NKSetNativeButtonImage;
this.id = CallNKitAction("NKCreateButton?sync=yes");
}
function NKSetNativeButtonImage(imageName)
{
CallNKitAction("NKSetNativeButtonImage?image="+imageName+"&id="+this.id);
}

function NKSetNativeButtonTitle(title)
{
CallNKitAction("NKSetNativeButtonTitle?title="+title+"&id="+this.id);
}

function NKPlaceNativeButton(x, y, width, height, callback)
{
CallNKitAction("NKPlaceNativeButton?x="+x+"&y="+y+"&width="+width+"&height="+height+"&callback="+callback+"&id="+this.id);
}

function NKShowNativeButton()
{
CallNKitAction("NKShowNativeButton?id="+this.id);
}
function NKHideNativeButton()
{
CallNKitAction("NKHideNativeButton?id="+this.id);
}



So, with this info in hand, I tried to write out the JavaScript. Doing "var btn = new NKButton ( ), and setting the properties every which way, didn't make a native button appear. Ok, I'll go with a NKNavigationController instead; this worked as expected, a nav controller appeared on the top of the emulator screen with a button, and a test event handler that shows an NKAlert worked. So far so good.

It then dawned on me that I wasn't thinking about this right; I'm supposed to be using HTML and JS, not trying to figure out how the standard iPhone SDK applies. So, let's shift thinking: I'll still use the NKNavigationController (though based on what I can see, the button should have worked...DOCS PLEASE!), but I'll also add a button under it that does the same thing; clicks and makes the image appear. For the image, I'll just put in an HTML "img" tag, with no "src" attribute specified. When I click either the button in the nav bar, or the standard HTML button, I'll call a JS function to load the image. Here's my code:


<html>
<head>
</head>
<body>
<script type="text/javascript" src="NKit.js"></script>

<script type="text/javascript">
var navController = new NKNavigationController ( );
navController.setTitle ( "Testing NimbleKit" );
navController.setStyle ( "black" );
navController.addNavigationItem ( "Image", "showImage" );

function showImage ( )
{
img.src = "cat.jpg";
}

</script>

<input type="button" value="Load Image", onClick="showImage ( )" />
<img id="img" src="" />

</body>
</html>


And I will be freakin' damned...they both worked perfectly. Screenshots below. I gotta say, I'm stunned. The potential for this development kit is pretty staggering when you think about it. The developer of NimbleKit has essentially put basic iPhone development into the hands of every basic web page developer.

You think there's a lot of apps in the iPhone store NOW...just wait 'til this gets out!

As always, thanks for visiting.




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.

Tuesday, June 2, 2009

Adobe Flash Builder (formerly Flex), first looks: Compatibility with older Flex, different namespaces...other immediate differences?

Adobe Flash Builder (formerly Flex), first look: Compatibility with older Flex, different namespaces...any other immediate differences?

Yesterday, Adobe announced the general availability of Flash Builder 4 Premium Beta, and Flash Catalyst, which I may or may not discuss some other day. The coder tool is Flash Builder, and that's my primary interest by far, though Catalyst does look interesting...and possibly headache inducing, as it's a way for non-coders to generate code without actually understanding it. Historically, that's always been a mess.

This article focuses on my initial experiments with Flash Builder, which is the new Flex, rebranded. I installed it on my only non-work machine, which is a Windows XP box. Apologies to the Mac loyalists.

My first concern is, can I use old Flex projects in the new Flash Builder? This is primary to me because, if you went through the whole wrestling match of Eclipse Flex Plugin projects vs. Flex Builder Projects vs. Flash projects (which really don't exist, it's just a folder with relatively located assets), and of course the whole CS3 to CS4 upgrades with subsequent months of, "I don't have Flash CS4 can you export to CS3...I don't have Photoshop CS4 can you downgrade the .psd," you know that it's EXTREMLY important that you be able to import old projects, and export new ones in the older formats. This still makes the whole SVN thing a mess if people are using different versions, but that's more a team workflow/standards thing; a team should agree on a version and all upgrade at the same time.

Anyway, I found some issues. I'm sure I'll find more, and of course it's possible there's more for me to learn about the new tool and V4 SDK, but this is where I'm at onDay 1.

On launch, the new Flash Builder looks pretty much identical to the old one. Screenshot below.







Right off the bat, when I go to the File menu, there it is: "Import Flex Project" and "Export Flex Project (FXP)" menu selections. Alrighty, let's try the import process on a fairly big Flex project, the codebase for my PlanetSudoku game.

After selecting the project folder (which I just dragged onto my Windows desktop from my Mac Flex Builder 3 workspace), a dialog popped up asking me what Flex SDK I wanted to use. The default is Flex 4.0, but I could select any other SDK I had installed (it appears to also install 3.4 for you, which is nice). Let's be daring: I'll compile it with 4.0.







Continuing on, I get the warning, "If you convert, you won't be able to use this project in older versions of Flash Builder...". Hmm, ok, I guess I could always just use the Export feature if I needed to...more on that later.

Note: If you are getting the idea into your head that you can start using the Beta full-time now because you can import and export projects, that is a BAD idea. BAD. It's a beta product, you should NOT use it for production work. And as you read on, you'll see how bad it can be.

Without trying to run it, the import worked, here's a shot of the project structure. Good 'ol bin-debug is still there, html-template, my asset folders, my sounds, all the structure looks like it imported cleanly. Note that "Flex 4.0" is now it's own library category, and there looks like there's some new things in there. That'll have to wait for another blog post.







Ok, no errors, let's open an ActionScript file and look at the code editor. Here's a nice surprise; all .as files are nodes, which when expanded, show the structured outline of the file, just like the "Outline" window. I guess that window is sort of redundant now, though it does have sorting options and such.







At first glance, things look pretty much the same in the code editor window, though there does seem to be some new icons to assist in scanning through the lists of auto complete selections, like below (notice the "Native" icon):







Ok, enough dinking around, let's run this thang...AHAH! When I go to the Run button, I see a new choice, something that appeals to the "enterprise" in me...Execute Flex Unit Tests! Clearly evidence that Adobe is getting more serious about the more serious coder. Gotta look that one up in the help files ("Help" appears identical to old Flex help FYI). More :







Help says the following about the FlexUnit Test Environment:

The FlexUnit test environment allows you to generate and edit repeatable tests that can be run from scripts or directly within Flash Builder. From Flash Builder, you can do the following:

Create unit test cases and unit test suites

Flash Builder wizards guide you through the creation of test cases and test suites, generating stub code for the tests.

Run the test cases and test suites

You can run test cases and test suites various ways from within Flash Builder or outside the Flash Builder environment. The results of the tests are displayed in a test application. Flash Builder opens a Flex Unit Results View for analysis of the test run.

Navigate to source code from the Flex Unit Results View

In the Test Results panel, double-click a test to open the test implementation.

The Test Failure Details panel lists the source and line number of the failure. If the listed source is in the current workspace, double-click the source to go directly to the failure.


Ok, that's definitely another blog article in the making. There's unit testing frameworks out there for Flex that I've seen, but integrated? That's significant.

So, back to running the project...ARGH. A browser window pops up, but then an ActionScript error window comes up with the following message:

"VerifyError: Error #1014: Class IAutomationObject could not be found."

Ok, I know it's probably fixable using SDK 4, however, what I'm going to try is deleting the entire project, and reimporting it using the 3.4 SDK (which is the only other one available in the dropdown; I might actually not have another Flex SDK installed on this machine, so it's nice they seem to install 3.4 for you).

First thing I notice; the Flex 4 folder is now Flex 3.4, and some of those "new things" are gone. Ok, so the Flex 4 SDK is quite a bit different than 3.4, that's good to know.

No errors, let's try running it...SUCCESS! The project ran just fine.

So, Compatibility Lesson 1: DON'T USE THE Flex 4 SDK FOR 3.x SDK PROJECTS. At least, not unless you're willing to wrestle with differences to use the newer one. Predictable, but now confirmed.

Now, let's try a Debug run. No surprises. Seems to work just like the old one.

Time to try it the other way around. I'll create a "Hello World" project in Flash Builder 4, using the V4 SDK, export it, and try to load it into Flex Builder 3.

When creating the new project, I notice it's not a "Flash Builder" project, it's still a "Flex Project." All the choices look identical to Flex 3.The project created as expected, but I noticed one thing: The top level MXML file still contains the Application element, but it looks different (note the "s" and "fx" namespace declarations):


<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/halo" minWidth="1024" minHeight="768">

</s:Application>


Application now falls under this namespace declaration: xmlns:s="library://ns.adobe.com/flex/spark". If you recall from the screenshot of the Flex 4 folder above, there is a .swc called "sparkskins". Hmm. Drastic changes afoot?

Aside from that, the dev tasks look the same. I'll drag 'n drop a button and a label, and set up the click event handler to populate label with "Hello Flash Builder Export Test!".

Bonk! When I went to type <mx:Script>, like I usually would, it didn't get recognized: no CDATA tags and closing </mx:Script> tags got generated. After a little dinking by looking at the declared namespaces, I found the Script tag in the fx namespace. This has the desired result...but oh jeezus. I'm going to have to unlearn some pretty basic things it seems.

The test code looks like this, and worked exactly as expected. Interestingly, no more weird Flex green background, it was just plain white (thank you Adobe...wtf was with that grey/green background anyway). No screenshot for this, just imagine a white background, with a Flex (erm..."Flash Builder") button, which when clicked, populates an mx:label (erm..."s:label"):


<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/halo" minWidth="1024" minHeight="768">

<fx:Script>
<![CDATA[
private function onClick ( event : MouseEvent ) : void
{
lbl.text = "Hello Flash Builder Export Test";
}
]]>
</fx:Script>


<s:Button x="192" y="28" label="Button" click="onClick ( event )"/>
<mx:Label id="lbl" x="96" y="86" text="Label" width="288"/>

</s:Application>



Export time. I'll use the File...Export Flex Project (FXP) option. This creates a Flex Project archive, which I should be able to import nicely. Here goes...

...not even close. Again, undoubtedly because I created the project using the Flex 4 SDK. Meh, I was curious, but this is exactly what I expected. so I'll recreate the project using the 3.4 version and re-export it. In the new 3.4 SDK project, I notice that the "mx" namespace is back, everything looks kosher, just change the "fx" and "s" namespaces to "mx", and the code ported over fine.

Over in the Flex Builder 3 UI...import FXP...BLEARGH! It didn't work. This simple little project, when imported into Flex Builder 3, failed. Wouldn't build, nothing in bin-debug, nada. So it seems, Lesson 2: at least for now, DON'T BUILD PROJECTS IN FLASH BUILDER AND EXPECT FLEX USERS TO BE ABLE TO EASILY IMPORT THEM!

Sure, as always, there's things I probably don't know, but I appear to be following the guidelines pretty straight. Time to RTFM, look at the help docs more carefully, etc.

Anyway, that's a long enough post. Thanks for coming along on my first tour of Adobe's new Flash Builder.