I just finished up a new Flex 2 component that allows you to add close icons to tabs that when clicked will remove them from a TabNavigator.
Here is the component in action:
When you click the "Add Tab" button, a new tab is created with the given label and icon. The display of the close icon depends on the state of showCloseIcon. When set to mouseOver, the close icon is only show when the mouse is over the table. Setting to true always shows the close icon, and setting to false always hides it. Note that in the above example, when changing the state of the close icon, the tabs needs to be removed and re-created. I didn't build in support to change the behavior on-the-fly because I didn't feel this was a common use case.
When a close icon is clicked, a new ItemCloseEvent is dispatched. You can listen for this event via the itemClose event in MXML. By default, the close icon will automatically remove the tab from the tab navigator. If you don't want this default behavior, you call event.preventDefault(); in the event handler and the tab will no longer be removed automatically. This is useful for having, say, a question mark instead of a close icon that when clicked can open a help document.
Lastly, the close icon can be specified via the closeIcon and overCloseIcon properties. I didn't build in support for a down icon because I didn't feel it was necessary, but doing so would require just a few minor tweaks to the code base.
This is a component that I built for the current client project I'm working on. Therefore, I'm not able to offer this for download, nor am I able to share the code with you. Everyone that knows me knows I'm a big fan of open source and a large contributor to OSFlash, so I'd share if I could...
This component was a little on the tricky side to write, but I hope it proves inspirational for developers out there. With Flash (and therefore Flex), you can pretty much do anything that you can imagine... it just takes a little time, ingenuity and determination. Honestly, I tried 3 different approaches to making this component before I was successful, but overall it was less than a day's work.
I'm sure there are some bugs to work out, but I'm pleased with how well it's turned out so far. It's a vital piece in the project that I'm working on...
Flex 2, Component, ActionScript 3