Wednesday, March 31, 2010

Tree Item ToolTips

Here is how you can set custom tooltips in Flex 3 on each item in a Tree.

First, you have to set the following properties on the Tree:
  • showDataTips="true" - causes tooltips to be shown
  • dataTipFunction="myDataTipFunction" - sets the function which returns the tooltip for each item
  • itemRenderer="ToolTipItemRenderer" - tells the tree to use our custom renderer (which extends the default TreeItemRenderer)
The itemRenderer isn't necessary unless you want to have control over where the tooltip is positioned (see below).

Also note that if you set the dataTipField property on the tree instead of the dataTipFunction then your tooltips will only show up when the tree item isn't fully visible due to scrollbars. By setting the dataTipFunction it forces the tooltips to always show when the mouse is over the tree node.

Now, on to the next problem. By using the method above the tooltips are always displayed. But the default position for the tooltip is right on top of the tree node, which is annoying. So this is why we use our own custom item renderer so that we can position the tooltip below or above the node (or anywhere you want it).

Here is an example with View Source enabled:

Wednesday, March 17, 2010

Custom Components Live Preview (Design Mode)

If you have created your own component and you drag it onto your Flex app in Design Mode and it appears as a tiny almost invisible square on your screen, then watch the video below to see how you can get it working properly (like the default controls do).

I found this awesome video tutorial on YouTube that explains how you can create what is called a Live Preview of your component so that your custom component actually appears with the right appearance and dimensions.

Be sure to check out the author's blog at

The end result that I learned from this video is that if you have a Flex Project which contains your custom component, and you try to use it in an MXML file then it won't work properly. If the custom component is in a separate Flex Library Project (or SWC) then it will work properly.

Thursday, March 4, 2010

DragHandle, ResizeHandle

Here are two customizable drag and resize handles:

You can set the following properties:
  • rows - sets the number of rows of dots
  • columns - sets the number of columns of dots
  • dotSize - sets the dot size (defaults to 2)
  • dropShadowEnabled - sets whether a drop shadow is used (defaults to false)
  • dropShadowColor - sets the drop shadow color
  • keepOnTop - if true then the handle will be on top of the other sibling components
  • positionResizeHandle - If true then the resize handle will be positioned in the bottom right corner of the parent (ResizeHandle only)
* Note: if you explicitly set the width and height of the DragHandle or ResizeHandle, then the rows and columns properties are ignored. In this case as many dots are rendered as will fit into that area.

You can set the following styles too:
  • backgroundColor, backgroundAlpha - sets the background color alpha for the drag/resize handle
  • dragHandleColor, dragHandleAlpha - sets the color and alpha value for the drag handle
  • resizeHandleColor, resizeHandleAlpha - sets the color and alpha value for the resize handle

These two components are used in all the Resizable Containers.