Dec 5 2006

Flex 2: Building an animated "Sometimes" DividedBox

Posted by Joe Rinehart at 8:01 AM
9 comments
- Categories: Flex

I've got a situation where I need to simulate the iTunes look of having a master list take up all of a panel's width/height, with the ability to optionally split the area into a divided box to show detail information.

With Flex 2, it's uber-easy to do this in a slick manner: you can just use a VDividedBox and states to add/remove the detail as the first child of the VDividedBox.

If you want to skip the explanation and see the finished product, it's available at:

http://www.firemoss.com/demos/flex/dividedbox/

Source code:

http://www.firemoss.com/demos/flex/dividedbox/srcview/index.html

I wanted to take this a bit further, though, and animate the transition. At first glance, you'd think you could do it by using two <mx:Transition> - one containing the <mx:Resize> that shows the detail, and another containing the <mx:Resize> that hides the detail.

Nope - it looks like the state change removes the detail area before playing the transition.

So, how can we get it to work? It's actually not bad at all: create a function called something like "hideDetail," move our "hide" resize our of a transition, and tell it to play hideDetail when it's done.

It wouldn't be hard to take this further, turning it into a reusable component extending the desired type of divided box.

Comments

darron

darron wrote on 12/05/06 9:35 AM

For the transition, look at using the mx:RemoveChildAction tag in a sequence effect after a resize effect. That will delay removing the child until after the resize is done.
Simeon

Simeon wrote on 12/05/06 9:54 AM

You could also use the &lt;mx:Sequence&gt; tag inside your transitions to control the order of the effects you apply. Then you can target the individual controls you want each effect applied to them. This will help you avoid the box appearing at the wrong time.
Joe Rinehart

Joe Rinehart wrote on 12/05/06 9:59 AM

Ah, thanks guys! I figured someone would post the right way....I feel like I'm learning CF again, reinventing wheels that aren't obvious in the docs, just to find out listQualify() exists...
Zach

Zach wrote on 12/05/06 5:59 PM

Joe, are using Flex Builder or hand coding your apps? Just curious....
Bruce

Bruce wrote on 12/05/06 9:43 PM

Thanks for posting this example. However, I had some problems using it. When I clicked on the second item in the data grid, the state changed and displayed the correct information in the detail area.

But after clicking on OK to close the detail area and then clicking on the first item, the detail area opens but still shows the second item's information.

Also, from a usability standpoint, when the detail state is visible, and the user clicks on a different item in the datagrid, the detail area should change.

When I put your code in my own Flex 2.0 project I get several warnings that
&quot;Data binding will not be able to detect assignments in artist&quot;
&quot;Data binding will not be able to detect assignments in currentAlbum&quot;

I'll play with your code and see what I can figure out.
Bruce

Bruce wrote on 12/05/06 9:50 PM

Ok. Reference my comment above. Change your code in your detail state to:

&lt;mx:State name=&quot;detail&quot;&gt;
&lt;mx:AddChild relativeTo=&quot;{box}&quot; position=&quot;firstChild&quot;&gt;
&lt;mx:Canvas id=&quot;detailCanvas&quot;&gt;
&lt;mx:VBox&gt;
&lt;mx:Text text=&quot;{masterGrid.selectedItem.artist}&quot; /&gt;
&lt;mx:Text text=&quot;{masterGrid.selectedItem.album}&quot; /&gt;
&lt;mx:Text text=&quot;{masterGrid.selectedItem.price}&quot; /&gt;
&lt;mx:Button label=&quot;Ok&quot; click=&quot;hideDetail()&quot; /&gt;
&lt;/mx:VBox&gt;
&lt;/mx:Canvas&gt;
&lt;/mx:AddChild&gt;
&lt;/mx:State&gt;

You want to bind the text components to the current selected item in your DataGrid.

Now there is one other usability problem to solve. If the user clicks on an item in the DataGrid and the detail state opens up and then the user clicks on the OK button to close the detail state, what happens when the user wants to reopen the detail state for the currently selected item in the data grid? Click on the already selected item doesn't open the detail state since you are using the change event to trigger opening the detail state.

Instead try using the click event as the trigger click=&quot;itemSelected()&quot;
Bruce

Bruce wrote on 12/05/06 9:54 PM

One more thing:

[Bindable]
private var albums:ArrayCollection = new ArrayCollection();

make your albums ArrayCollection object Bindable since you bind it to the dataProvider for your DataGrid.
Sam Shrefler

Sam Shrefler wrote on 12/06/06 11:56 AM

Try changing the position in your state from &quot;firstChild&quot; to &quot;lastChild&quot;. It doesn't work anymore :-( Any ideas why that would happen?
Jeff

Jeff wrote on 09/29/08 2:12 AM

But after clicking on OK to close the detail area and then clicking on the first item, the detail area opens but still shows the second item's information.
http://www.batteryfast.co.uk/compaq/n110.php Original Battery Compaq Evo N110 N110S PP2101X NEW laptop battery,
http://www.batteryfast.co.uk/compaq/372114-001.php Battery for HP/COMPAQ NX1050 NX9000 NX9005 NX901 laptop battery,
http://www.batteryfast.co.uk/dell/312-0306.php NEW battery for Inspiron 700M 710M 312-0306 G5345 C7786 laptop battery,
http://www.batteryfast.co.uk/dell/2k184.php New 7.4V battery fits DELL Latitude X200 312-0058 8U443 laptop battery,
http://www.batteryfast.co.uk/dell/312-0079.php NEW Battery fit Dell Inspiron 5150 5160 1100 1150 5100 laptop battery,
http://www.batteryfast.co.uk/dell/d620.php Batteries Latitude D620 NT379 312-038 dell black laptop battery,

http://www.batteryfast.co.uk/dell/312-0079-2.php NEW Battery fit Dell Inspiron 5150 5160 1100 1150 5100 laptop battery,
http://www.batteryfast.co.uk/dell/e1505.php NEW DELL INSPIRON 6400 E1505 1501 85 WHr 9 BATTERY laptop battery,
http://www.batteryfast.co.uk/dell/6400.php NEW DELL INSPIRON 6400 E1505 1501 85 WHr 9 BATTERY laptop battery,
http://www.batteryfast.co.uk/dell/312-0335.php New GENUINE 8-Cell Dell Inspiron 1000 1200 2200 Battery laptop battery,
http://www.batteryfast.co.uk/dell/312-0451.php New Dell Inspiron M140 640m 630m E1405 laptop battery,
http://www.batteryfast.co.uk/dell/d820.php New Dell Precision m65 D820 Battery HICAPACITY 312-039 laptop battery,

http://www.batteryfast.co.uk/dell/w1605.php Battery for DELL Latitude D500 D600 Inspiron 500m 600m laptop battery,
http://www.batteryfast.co.uk/dell/312-0009.php DELL INSPIRON 8000 8100 8200 BATTERY 75UYF 66WHR 1691P laptop battery,
http://www.batteryfast.co.uk/dell/0u003.php NEW Laptop Battery For Dell Latitude D400 9T119 312-009 laptop battery,
http://www.batteryfast.co.uk/hp/dv9000.php New OEM HP HSTNN-LB33 dv9000 DV9000 dv9600 laptop battery,
http://www.batteryfast.co.uk/hp/f2024.php Battery For HP XE3 XE3B XE3C XE3L F2024 F2024B laptop battery,
http://www.batteryfast.co.uk/hp/hstnn-c16c.php Battery fits HP Pavilion DV8000 DV8100 DV8200 laptop battery,

Write your comment



(it will not be displayed)