Adding a little polish to DataGroups : transition one after another

Populating any Flex component with data is easy. But don’t stop there. Give it some polish by adding transitions when the data changes. Here’s a rather crude explorer where you can change the data and the transition method.

Note: one visitor reported that when selecting rotateInHorizontal or Vertical that it crashed his browser. I’m on a PC and had no issues with Chrome, FF, or IE. If you’re on a sub-PC ( Mac ) then you might want to proceed with caution. Or better yet upgrade to a PC. :)

view source

It is simple to add a transition. Just do the following:

1 – Declare a transition inside <fx:Declarations> of your <s:ItemRenderer />

<s:Fade id="fadeBtnIn" target="{ btn }"
	duration="{ 500 + ( this.itemIndex * 250 ) }"
	alphaFrom="0" alphaTo="1" />

I think it looks a little boring to have every element transition at the same time. To fix that I’m adjusting the duration of each element depending on its itemIndex.

2 – Initiate the transition. You have to do this twice. Once for creationComplete and then every time the data changes with dataChange.

<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/mx"
	width="100%"
	creationComplete="init()"
	dataChange="onDataChange();">

That’s pretty much all it takes.

Problems to look out for
I noticed a few things while putting this together. First, you’ll want to watch for what you’re <DataGroup> is embeded in and how it’s positioned. I originally had the vertical DataGroup aligned by horizontalAlign=”0″. That didn’t go over very well. The framework tries to position it horizontally when elements are transitioning. It’s not a pretty sight. :)

Perhaps I did something wrong and don’t see it but moveInBottom doesn’t seem to work very well for either DataGroup. The last element in the group just sort of giggles around. And with movieInTop the vertical group looks a little off. The top item goes all the way to the bottom and then back up again. Not sure what’s up with that.