Use getchildat () and setstyle () in flex to set a single tabbar tab Style

Source: Internet
Author: User
  1. <? XML version = "1.0"?>
  2. <Mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml"
  3. Layout = "vertical"
  4. Verticalalign = "Middle"
  5. Backgroundcolor = "white">
  6. <Mx: SCRIPT>
  7. <! [CDATA [
  8. Import MX. Events. itemclickevent;
  9. Import MX. Controls. tabbarclasses. tab;
  10. Private function tabbar_creationcomplete (): void {
  11. VaR colorarr: array = ["red", "haloorange", "yellow", "halogreen", "haloblue"];
  12. VaR color: string;
  13. VaR tab: tab;
  14. VaR idx: uint;
  15. VaR Len: uint = tabbar. dataprovider. length;
  16. For (idx = 0; idx <Len; idx ++ ){
  17. VaR I: Int = idx % colorarr. length;
  18. Color = colorarr [I];
  19. Tab = tab (tabbar. getchildat (idx ));
  20. Tab. setstyle ("fillcolors", [color, "White"]);
  21. Tab. setstyle ("fillalphas", [1.0, 1.0]);
  22. Tab. setstyle ("backgroundcolor", color );
  23. }
  24. }
  25. Private function tabbar_itemclick (EVT: itemclickevent): void {
  26. Viewstack. selectedindex = EVT. index;
  27. }
  28. ]>
  29. </MX: SCRIPT>
  30. <Mx: array id = "arr">
  31. <Mx: Object Label = "red"/>
  32. <Mx: Object Label = "orange"/>
  33. <Mx: Object Label = "yellow"/>
  34. <Mx: Object Label = "green"/>
  35. <Mx: Object Label = "blue"/>
  36. </MX: array>
  37. <Mx: tabbar id = "tabbar"
  38. Dataprovider = "{arr }"
  39. Creationcomplete = "tabbar_creationcomplete ();"
  40. Itemclick = "tabbar_itemclick (event);"/>
  41. <Mx: viewstack id = "viewstack"
  42. Width = "{tabbar. Width }"
  43. Stylename = "plain">
  44. <Mx: vbox id = "redvbox" width = "100%" Height = "100">
  45. <Mx: Label text = "Red vbox"/>
  46. </MX: vbox>
  47. <Mx: vbox id = "orangevbox" width = "100%" Height = "100">
  48. <Mx: Label text = "Orange vbox"/>
  49. </MX: vbox>
  50. <Mx: vbox id = "yellowvbox" width = "100%" Height = "100">
  51. <Mx: Label text = "Yellow vbox"/>
  52. </MX: vbox>
  53. <Mx: vbox id = "greenvbox" width = "100%" Height = "100">
  54. <Mx: Label text = "Green vbox"/>
  55. </MX: vbox>
  56. <Mx: vbox id = "bluevbox" width = "100%" Height = "100">
  57. <Mx: Label text = "Blue vbox"/>
  58. </MX: vbox>
  59. </MX: viewstack>
  60. </MX: Application>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.