Flex 2 Component - Draggable TabBar with close button

This is a total re-write of this (it was made during beta 2 or 3 and since then a lot of things had changed when Flex 2 Final came out).
After I posted the peice several people had asked for the source, so I took the chance last week to revise it a bit and clean up the code.
This is a much simplified and elegant version, I managed to add the close button on each tab directly without going too deep into the inheritance chain, you can see this in MyButton.as, that’s where all magic happens.
Code are heavily commented in Chinese and partially in English (I have confidence that I will forget what I’m doing six months later, so I comment almost each block of the code).
Feel free to drop me a line if there’s any question or improvement ideas, thanks.


13 Comments Add your own
1. barry.b&hellip | August 2nd, 2006 at 2:57 pm
umm… what’s in
import com.richtech.utils.Util;
anything important?
?
2. jeremy&hellip | August 2nd, 2006 at 3:21 pm
nope, just some custom debugging utilities.
3. Cames&hellip | August 3rd, 2006 at 10:10 pm
很實用的元件,謝啦!
雖然我還是c當作標準開發語言。
4. Rostislav Siryk&hellip | August 8th, 2006 at 2:03 am
Jeremy, this is very good job. Firefox 2.0-style tabs — really great!
I’m just wondering why you don’t post your gem to flexcomponents mailing list — surely people will like it!
5. Rostislav Siryk&hellip | August 8th, 2006 at 7:17 am
Also, maybe its a good idea to add “View Source” feature to the sample context menu?
6. jeremy&hellip | August 8th, 2006 at 10:09 am
hi Rostislav,
Thanks for the kind words, I didn’t post it on flexcomponents list because everyone there are also on flexcoders, no need to cross-posting.
I will add “view source” soon, thanks for the suggestion.
7. ncelq&hellip | August 8th, 2006 at 3:03 pm
Your site is great!
did you notice that, after creating a new tab, the memory usage (from task manager) is keep increasing, even if we click the close button to close the tag, the memory remains the same.
it seems that it is memory leakage for flex 2.
do you have any idea on how to free up memory?
8. jeremy&hellip | August 8th, 2006 at 3:15 pm
This is interesting, I didn’t noticed that, will look into it and see what I can do.
9. ncelq&hellip | August 8th, 2006 at 4:12 pm
yes, it is interesting, indeed, i have followed the following URL to create and remove a popup window. and it found that the same problem occurred (i.e. when create a new popup, memory keep increasing; when close the windows, the memory cannot free up still).
http://livedocs.macromedia.com/flex/2/docs/00000697.html#254176
10. jeremy&hellip | August 10th, 2006 at 6:46 pm
Memory leaking is a huge potential problem in Flex 2 (and the framework), this issue had been addressed several time before.
The conclusion often leads to :
1. make sure you have no reference of the DisplayObject, it may be stored in an Array, Dictionary.
2. use weak reference in addEventListener(), otherwise garbage collector won’t clean it up.
I had personally experience memory leakage problems several times so now I’m very carefully handling all references (popup windows…etc) created.
This gonna haunt every flex developer (and after a short while, flash 9 users) in the years to come.
11. jeremy&hellip | August 10th, 2006 at 6:50 pm
btw, another thing to note while dealing with memory in Flex 2.
when flex application starts, it gets an certain amount of memory from the system, garbage collector will not kick in right after a display object is removed from the list.
there are basically two rules, first is when the memory allocated are all used, GC will kick in, another is when the reference conunting table is full, GC will kick in.
so if you want to test with creating and removing popup windows, you might have to create 10000 windows at the same time (so the memory will all be consumed or reference table will be filled up) then remove them, you shall see the memory drops quickly.
12. Eduardo&hellip | May 11th, 2007 at 1:58 am
Great job!
13. Medal&hellip | July 18th, 2007 at 1:38 pm
Great!! 很棒的组件,收藏了,谢谢!
Trackback this post | Subscribe to the comments via RSS Feed