2009
09.03

It turns out that Flex 3.4 may not have been ready for the spotlight. Sure, I’m as eager as anyone to get a hold on it, especially since I had a part in its creation. However, there’s a horrible bug in the HTTPService world.

If you add a responder to a token created by the send() method, you’ll end up with two calls to the responder for every return by the server. The workaround is use event listeners rather than responders, but a lot of people (myself included) aren’t interested in rewriting legacy code to work around something that worked in a prior version.

Related Posts (generated):

2009
08.21

While sitting in #flex on Freenode a while back, someone asked how to use Twitter within Flex. Since I’ve meddled with other APIs I offered some advice, but I’d never personally dealt with Twitter. Douglas Knudsen pointed out at his 360|Indy session that no true web mashup is complete without using twitter so here is how to “complete” your own project.

With that in mind (and a fresh Flash Builder 4 Beta install) I figured what better way to learn a little about Spark than to create a Twitter Flex app? Since I was intending on posting it as a how-to, I kept it simple and sweet. Of course, it should be easy to take the code snippets and move them to your own mega-app.

I thought the first step was to learn the Twitter API, until I discovered there already existed projects out there that already took care of that. Thanks to the open source library tweetr, I just have to have a vague idea about twitter and let tweetr do the heavy lifting. No worrying about value objects or dealing with XML, just a simple event listener. So, with that I got to focus on Spark, which I’d never dealt with before.

If you want to see the final output (and view source) I’ve posted it here.

The search code to work with Tweetr is very simple. I simply add an eventListener for the COMPLETE event and shove the results into a bindable ArrayCollection. I’ve bound the search function to the enter & click events of a Spark TextInput and Button, but since they operate just like their MX components, it’s not really interesting to look at.

?View Code ACTIONSCRIPT3
[Bindable]
private var _searchResults:ArrayCollection = new ArrayCollection();
 
private function search():void {
	var tweetr:Tweetr = new Tweetr;
 
	tweetr.addEventListener(TweetEvent.COMPLETE, searchResults, false, 0, true);
	tweetr.search(searchInput.text);
}
 
private function searchResults(event:TweetEvent):void {
	_searchResults.source = event.responseArray;
	_searchResults.refresh();
}

Using MX, I’d normally bind that data to some sort of DataGrid or Repeater, but Spark has neither. But, thanks to Flash Builder’s code hinting, I discovered the DataGroup component. It’s somewhat like a repeater, but with more layout options thanks to the way layouts work in Spark.

?View Code ACTIONSCRIPT3
<s:DataGroup
	dataProvider="{_searchResults}"
	itemRenderer="com.enigmaticthought.components.TweetBox" width="100%">
	<s:layout>
		<s:VerticalLayout />
	</s:layout>
</s:DataGroup>

So all I had left was to create a renderer for the data. That’s where TweetBox came in to play. Its base class is a Spark ItemRenderer, which was a little tricky to deal with because I had to define states for it, even though I didn’t use any states. This is because the ItemRenderer uses states to handle things like hover and select to make the component customizable.

To fill in the TweetBox, I simply overrode the set data function and assigned all the values to the display components. Sadly, SearchResultData was not built as Bindable, so I couldn’t just let data binding do the work.

?View Code ACTIONSCRIPT3
import com.swfjunkie.tweetr.data.objects.SearchResultData;
private var _tweet:SearchResultData;
 
override public function set data(value:Object) : void {
	super.data = value;
	_tweet = value as SearchResultData;
	if (_tweet) {
		tweetImage.source = _tweet.userProfileImage;
		tweetText.text = _tweet.text;
		tweetAuthor.text = _tweet.user;
	}
}

One other thing to note is that while I could use Spark components for the text data, the image is still an MX component. There isn’t any plan for a Spark Image in Flex 4, but this is a good example of how mixing Spark & MX works.

?View Code ACTIONSCRIPT3
<s:ItemRenderer
	xmlns:fx="http://ns.adobe.com/mxml/2009"
	xmlns:s="library://ns.adobe.com/flex/spark"
	xmlns:mx="library://ns.adobe.com/flex/halo"
	width="100%">
	<s:layout>
		<s:HorizontalLayout/>
	</s:layout>
--------------------------------------------
...State & Code Removed...
--------------------------------------------
	<mx:Image id="tweetImage" height="48" width="48" scaleContent="true" />
	<s:VGroup id="textGroup" width="100%">
		<s:SimpleText id="tweetText" width="100%" explicitMaxWidth="{textGroup.width}" />
		<s:SimpleText id="tweetAuthor" width="100%" textAlign="right"/>
	</s:VGroup>
</s:ItemRenderer>

And now I have a really simple twitter search application. So, what are some of the other uses for Twitter, other than e-stalking people? You could build a new alert system that watches Twitter Trends to see what’s in the news, or use the search to keep an eye on a company, team, movie, TV Show, or stock. Of course, may you just want to amuse yourself.

Related Posts (generated):

2009
08.19

the Flex 4, aka Gumbo, Open Iteration Meeting (recording here) dealt primarily with the work Adobe plans to do to bring parity (or near parity) between new Flex 4 components and the old Flex 3 components and the transition from Flex 3 to Flex 4.

Just to review, the new component and skinning architecture has been dubbed Spark. Halo, now referred to as MX, is the current Flex architecture and will eventually fade into the sunset (or Flex 5). That doesn’t mean Halo will go away, just that the goal is to transition new users and applications to Spark. They also emphasized that with Flex 4, you may not be able to create a pure Spark application due to lack of Spark components. With Flex 5 being the targeted release for the ability to replace all the MX system with the Spark components. Thus Flex 4 will be a boundary release, allowing a user to mix in Spark components alongside the existing MX components.

The primary driver of Spark will be Flash Builder 4 & Catalyst. In the meeting we were told that Flash Builder 4 will offer a new choice when creating a Flex project. Whether to use Spark/Halo or Just Halo. This will alter the auto-complete and code hinting suggestions. The user can still use one or both, but this will allow Adobe to shape the experience toward Spark. Thus allowing a more natural feeling transition without an forced choice that will lock a user down. Catalyst will require Spark for the output it creates.

There will also be a separation of the theme and the components themselves. There will be both Spark and MX components, and they will be named separately from the TBD (“Spark”) theme and the Halo theme. So the look & feel will be separated from the functionality. No name exists for the “Spark” theme, but after the suggestion of “Fire” or “Smoke” by Simeon Bateman, Matt Chotin replies “but we were thinking along those lines :-)

Along with this news, the presentation went through a good bit of Spark components. Adobe is working on better Spark/MX container compatibility. That may mean adjusting some MX components as well to unify them using Interfaces rather than hard classes. Each Spark component had a nice “what we’re fixing” list as well. The end goal is not to clone a MX component’s functionality but to work out the most features while keeping things simple. One example was that instead of having border styles of many components, a border container was created that would allow a border to be created around a single or many components.

Currently Flex 4 is targeted Early 2010 with a Late 2009 second beta.

Other handy links:
Differences between Flex 3 and Flex 4
What’s new in Flex 4 beta

Related Posts (generated):

2009
08.18

Today, Aug 18th, there is a Open Iteration Meeting from 10am – 11am PDT. That’s noon – 1pm local time for me, but I’ll be there, lurking in the background.

The official link is here but if you miss the meeting, there will be a summary at the Gumbo Opensource Site.

Related Posts (generated):

2009
08.11

Flex SDK bug SDK-16241 was interesting for two reasons. It was claimed then abandoned (it shouldn’t take 4 months to patch) and the “Expected Result” was actually incorrect. Lots of bugs are claimed the abandoned. I admit I did it at the BugQuash when I realized I was over my head and should move on rather than flail around for the rest of the day. The expected result threw me though.

The problem lies with Scientific Notation and it’s formatting when converted to string using NumberFormatter, which doesn’t take into account the altered decimal position. Since we’re dealing with strings in the function itself, flex doesn’t have to worry about the size of the number, so I simply built the number up to full size and send it down the line. The same problem was in the NumberBase class when adding the thousands separator via formatThousands since it converts the Object->Number->String which returns my fancy long string to scientific notation. Since I’d already solved the problem, I just copied some code over. Both places needed to be fixed because only the numbers to the right of the decimal are sent to the formatThousands function.

I also learned that when talking precision, flex means number of decimal places, not significant digits. A major distinction mentioned in the NumberBase reference.

So what about the “expected result”? Well the value being formatted is -2.34444444444434e+21 which expands out to -2,344,444,444,444,340,000,000. The expected result is listed as -2,344,444,440,000,000,000,000 for some reason. I assume it’s someone’s calculator rounding off to a numerical precision of 9 since the actual value of 235345-242+99209323-2344444444444444444444 is -2344444444444345000018 which also tells me that flex’s default numerical precision is 15.

My patch is SDK-22643 if you’re interested.

Related Posts (generated):

Switch to our mobile site