Flex中如何去掉ComboBox竖直方向分割符的例子

下面是main.mxml:

  1. <? xml version = " 1.0 " encoding = " utf-8 " ?>
  2. <!-- http://blog.flexexamples.com/2009/03/23/removing-the-vertical-separator-from-the-combobox-control-in-flex/ -->
  3. < Application name = " ComboBox_skin_test "
  4. xmlns = " http://www.adobe.com/2006/mxml "
  5. backgroundColor = " white " >
  6. < ComboBox id = " comboBox "
  7. dataProvider = " [The,Quick,Brown,Fox,Jumps,Over,The,Lazy,Dog] "
  8. skin = " CustomComboBoxSkin " />
  9. </ Application >

下面是CustomComboBoxSkin.as:

  1. package {
  2. import flash . display . GradientType ;
  3. import flash . display . Graphics ;
  4. import mx . skins . halo . ComboBoxArrowSkin ;
  5. import mx . skins . halo . HaloColors ;
  6. import mx . styles . StyleManager ;
  7. import mx . utils . ColorUtil ;
  8. public class CustomComboBoxSkin extends ComboBoxArrowSkin {
  9. private static var cache : Object = {} ;
  10. public function CustomComboBoxSkin () {
  11. super () ;
  12. }
  13. private static function calcDerivedStyles ( themeColor : uint , borderColor : uint , fillColor0 : uint , fillColor1 : uint ) : Object {
  14. var key : String = HaloColors . getCacheKey ( themeColor , borderColor , fillColor0 , fillColor1 ) ;
  15. if ( ! cache [ key ]) {
  16. var o : Object = cache [ key ] = {} ;
  17. HaloColors . addHaloColors ( o , themeColor , fillColor0 , fillColor1 ) ;
  18. }
  19. return cache [ key ] ;
  20. }
  21. override protected function updateDisplayList ( w : Number , h : Number ) : void {
  22. super . updateDisplayList ( w , h ) ;
  23. var arrowColor : uint = getStyle ( " iconColor " ) ;
  24. var borderColor : uint = getStyle ( " borderColor " ) ;
  25. var cornerRadius : Number = getStyle ( " cornerRadius " ) ;
  26. var dropdownBorderColor : Number = getStyle ( " dropdownBorderColor " ) ;
  27. var fillAlphas : Array = getStyle ( " fillAlphas " ) ;
  28. var fillColors : Array = getStyle ( " fillColors " ) ;
  29. StyleManager . getColorNames ( fillColors ) ;
  30. var highlightAlphas : Array = getStyle ( " highlightAlphas " ) ;
  31. var themeColor : uint = getStyle ( " themeColor " ) ;
  32. // The dropdownBorderColor is currently only used
  33. // when displaying an error state.
  34. if ( ! isNaN ( dropdownBorderColor )) {
  35. borderColor = dropdownBorderColor ;
  36. }
  37. var derStyles : Object = calcDerivedStyles ( themeColor , borderColor , fillColors [ 0 ] , fillColors [ 1 ]) ;
  38. var borderColorDrk1 : Number = ColorUtil . adjustBrightness2 ( borderColor , - 50 ) ;
  39. var themeColorDrk1 : Number = ColorUtil . adjustBrightness2 ( themeColor , - 25 ) ;
  40. var cornerRadius1 : Number = Math . max ( cornerRadius - 1 , 0 ) ;
  41. var cr : Object = { tl : 0 , tr : cornerRadius , bl : 0 , br : cornerRadius } ;
  42. var cr1 : Object = { tl : 0 , tr : cornerRadius1 , bl : 0 , br : cornerRadius1 } ;
  43. var arrowOnly : Boolean = true ;
  44. // If our name doesn't include "editable", we are drawing the non-edit
  45. // skin which spans the entire control
  46. if ( name . indexOf ( " editable " ) < 0 ) {
  47. arrowOnly = false ;
  48. cr . tl = cr . bl = cornerRadius ;
  49. cr1 . tl = cr1 . bl = cornerRadius1 ;
  50. }
  51. var g : Graphics = graphics ;
  52. g . clear () ;
  53. // Draw the border and fill.
  54. switch ( name ) {
  55. case " upSkin " :
  56. case " editableUpSkin " : {
  57. var upFillColors : Array = [ fillColors [ 0 ] , fillColors [ 1 ] ] ;
  58. var upFillAlphas : Array = [ fillAlphas [ 0 ] , fillAlphas [ 1 ] ] ;
  59. // border
  60. drawRoundRect ( 0 , 0 , w , h , cr ,
  61. [ borderColor , borderColorDrk1 ] , 1 ,
  62. verticalGradientMatrix ( 0 , 0 , w , h ) ,
  63. GradientType . LINEAR , null ,
  64. { x : 1 , y : 1 , w : w - 2 , h : h - 2 , r : cr1 }) ;
  65. // button fill
  66. drawRoundRect ( 1 , 1 , w - 2 , h - 2 , cr1 ,
  67. upFillColors , upFillAlphas ,
  68. verticalGradientMatrix ( 1 , 1 , w - 2 , h - 2 )) ;
  69. // top highlight
  70. drawRoundRect ( 1 , 1 , w - 2 , ( h - 2 ) / 2,
  71. { tl: cornerRadius1, tr: cornerRadius1, bl: 0, br: 0 },
  72. [ 0xFFFFFF, 0xFFFFFF ], highlightAlphas,
  73. verticalGradientMatrix(1, 1, w - 2, (h - 2) / 2 ) );
  74. break ;
  75. }
  76. case " overSkin " :
  77. case " editableOverSkin " : {
  78. var overFillColors : Array ;
  79. if ( fillColors . length > 2 ) {
  80. overFillColors = [ fillColors [ 2 ] , fillColors [ 3 ] ] ;
  81. } else {
  82. overFillColors = [ fillColors [ 0 ] , fillColors [ 1 ] ] ;
  83. }
  84. var overFillAlphas : Array ;
  85. if ( fillAlphas . length > 2 ) {
  86. overFillAlphas = [ fillAlphas [ 2 ] , fillAlphas [ 3 ] ] ;
  87. } else {
  88. overFillAlphas = [ fillAlphas [ 0 ] , fillAlphas [ 1 ] ] ;
  89. }
  90. // border
  91. drawRoundRect ( 0 , 0 , w , h , cr ,
  92. [ themeColor , themeColorDrk1 ] , 1 ,
  93. verticalGradientMatrix ( 0 , 0 , w , h ) ,
  94. GradientType . LINEAR , null ,
  95. { x : 1 , y : 1 , w : w - 2 , h : h - 2 , r : cr1 }) ;
  96. // button fill
  97. drawRoundRect ( 1 , 1 , w - 2 , h - 2 , cr1 ,
  98. overFillColors , overFillAlphas ,
  99. verticalGradientMatrix ( 1 , 1 , w - 2 , h - 2 )) ;
  100. // top highlight
  101. drawRoundRect ( 1 , 1 , w - 2 , ( h - 2 ) / 2,
  102. { tl: cornerRadius1, tr: cornerRadius1, bl: 0, br: 0 },
  103. [ 0xFFFFFF, 0xFFFFFF ], highlightAlphas,
  104. verticalGradientMatrix(0, 0, w - 2, (h - 2) / 2 ) );
  105. break ;
  106. }
  107. case " downSkin " :
  108. case " editableDownSkin " : {
  109. // border
  110. drawRoundRect ( 0 , 0 , w , h , cr ,
  111. [ themeColor , themeColorDrk1 ] , 1 ,
  112. verticalGradientMatrix ( 0 , 0 , w , h )) ;
  113. // button fill
  114. drawRoundRect ( 1 , 1 , w - 2 , h - 2 , cr1 ,
  115. [ derStyles . fillColorPress1 , derStyles . fillColorPress2 ] , 1 ,
  116. verticalGradientMatrix ( 1 , 1 , w - 2 , h - 2 )) ;
  117. // top highlight
  118. drawRoundRect ( 1 , 1 , w - 2 , ( h - 2 ) / 2,
  119. { tl: cornerRadius1, tr: cornerRadius1, bl: 0, br: 0 },
  120. [ 0xFFFFFF, 0xFFFFFF ], highlightAlphas,
  121. verticalGradientMatrix(1, 1, w - 2, (h - 2) / 2 ) );
  122. break ;
  123. }
  124. case " disabledSkin " :
  125. case " editableDisabledSkin " : {
  126. var disFillColors : Array = [ fillColors [ 0 ] , fillColors [ 1 ] ] ;
  127. var disFillAlphas : Array = [ Math . max ( 0 , fillAlphas [ 0 ] - 0.15 ) , Math . max ( 0 , fillAlphas [ 1 ] - 0.15 ) ] ;
  128. // border
  129. drawRoundRect ( 0 , 0 , w , h , cr ,
  130. [ borderColor , borderColorDrk1 ] , 0.5 ,
  131. verticalGradientMatrix ( 0 , 0 , w , h ) ,
  132. GradientType . LINEAR , null ,
  133. { x : 1 , y : 1 , w : w - 2 , h : h - 2 , r : cr1 }) ;
  134. // button fill
  135. drawRoundRect ( 1 , 1 , w - 2 , h - 2 , cr1 ,
  136. disFillColors , disFillAlphas ,
  137. verticalGradientMatrix ( 0 , 0 , w - 2 , h - 2 )) ;
  138. arrowColor = getStyle ( " disabledIconColor " ) ;
  139. break ;
  140. }
  141. }
  142. // Draw the triangle.
  143. g . beginFill ( arrowColor ) ;
  144. g . moveTo ( w - 11.5 , h / 2 + 3);
  145. g.lineTo(w - 15, h / 2 - 2 ) ;
  146. g . lineTo
分享到:
评论

你可能感兴趣的:(cache,Flex,Blog,Flash,Adobe)