Flex 4: Random Layout and Step Layout

August 22, 2009

Yesterday at the Bangalore Flex User Group Meeting after Khan’s excellent talk on LCDS3, Fiber and the Modeler Plugin we had some time left to so I decided to show everyone how cool and easy layouts in Flex 4 are ..

Here are two quick layouts we wrote during the meeting as I showed everyone how easy it is to write a custom layout …

Random Layout

Step Layout

These layouts are currently somewhat crude but the idea was to convey how easy it is to write your own layouts … here the code for RandomLayout … just one simple function …

Of course, these layout algorithms can get more complex … here’s the StepLayout code …

For more elaborate examples you may want to checkout the ConcentricLayout example I posted last week or Ryan Campbell’s very cool 3D Layouts. Evtim, an engineer on the Flex SDK team also has some detailed posts on how to write Layouts on his blog.

Flex 4 is awesome.


UPDATE: You can view the complete source of the above example here or download it from here.


5 Responses - What do you think?

  1. Interesting to see these. Unfortunately I don’t do a lot of Flex but I thought I would share one of my random layout classes with you. http://wonderfl.net/code/63d40f01f056667cf926d78359f7e45eb0a9fb48 This does a random scatter with no overlapping. Would be interested in seeing if it can be used with Flex’s layouts, may be the inspiration I need to give Flex 4 a try again.

  2. Jesse,

    Neat little layout class you have there … shouldn’t take much to translate it to play well with Flex 4 … you should give it a try.
    If I ever need a random layout in a project .. I’ll pick on your algorithm .. thanks for sharing.
    _
    Mrinal

  3. Couldn’t we make a Organizational chart using this kind of code? Just wondering because I tried to create something like this and it didn’t work for me.

  4. @rconr007 you can write similar code that modifies x,y position based on data to create an Org chart but for that you would write a regular Component.

    As far as I understand them, Layouts are not meant to deal with data, they generally only interact with the ILayoutElement or IVisualElement interface of group’s children

  5. [...] ejemplos de layouts Layout concéntrico Random layout Artículo sobre layouts Wheel [...]

Your thoughts or questions: