http://blog.minidx.com/2009/11/05/3021.html

下面是main.mxml:

  1. xml version="1.0" encoding="utf-8"?>
  2. <s:Application name="Halo_Alert_borderSkin_test"
  3. xmlns:fx="http://ns.adobe.com/mxml/2009"
  4. xmlns:s="library://ns.adobe.com/flex/spark"
  5. xmlns:mx="library://ns.adobe.com/flex/halo">
  6.  
  7. <fx:Style>
  8. @namespace s "library://ns.adobe.com/flex/spark";
  9. @namespace mx "library://ns.adobe.com/flex/halo";
  10.  
  11. mx|Alert {
  12. borderSkin: Cla***eference("skins.CustomPanelBorderSkin");
  13. }
  14. fx:Style>
  15.  
  16. <fx:Script>
  17. import mx.controls.Alert;
  18.  
  19. protected function btn_clickHandler(evt:MouseEvent):void {
  20. var a:Alert = Alert.show("The quick brown fox jumps over the lazy dog", "Alert title");
  21. a.status = mx_internal::VERSION;
  22. }
  23. ]]>
  24. fx:Script>
  25.  
  26. <mx:ApplicationControlBar width="100%" cornerRadius="0">
  27. <s:Button id="btn"
  28. label="Launch Alert"
  29. click="btn_clickHandler(event);" />
  30. mx:ApplicationControlBar>
  31.  
  32. s:Application>

下面为skins/CustomPanelBorderSkin.mxml的代码:

  1. xml version="1.0" encoding="utf-8"?>
  2. <s:SparkSkin name="CustomPanelBorderSkin"
  3. xmlns:fx="http://ns.adobe.com/mxml/2009"
  4. xmlns:s="library://ns.adobe.com/flex/spark"
  5. implements="mx.core.IRectangularBorder">
  6.  
  7. <fx:Script>
  8. import mx.core.EdgeMetrics;
  9. import mx.core.IUIComponent;
  10.  
  11. /* Define the skin elements that should not be colorized.
  12. For panel, border and title backround are skinned, but the content area and title text are not. */
  13. static private const exclusions:Array = ["background"];
  14. override public function get colorizeExclusions():Array {
  15. return exclusions;
  16. }
  17.  
  18. /* Define the content fill items that should be colored by the "contentBackgroundColor" style. */
  19. static private const contentFill:Array = [];
  20. override public function get contentItems():Array {
  21. return contentFill
  22. };
  23.  
  24. private var _metrics:EdgeMetrics = new EdgeMetrics(1, 32, 1, 1);
  25. public function get borderMetrics():EdgeMetrics {
  26. var hasPanelParent:Boolean = isPanel(parent);
  27. var controlBar:IUIComponent = hasPanelParent ? Object(parent).mx_internal::_controlBar : null;
  28. if (controlBar && controlBar.includeInLayout) {
  29. _metrics.bottom = controlBar.getExplicitOrMeasuredHeight() + 1;
  30. } else {
  31. _metrics.bottom = 1;
  32. }
  33. return _metrics;
  34. }
  35.  
  36. public function get backgroundImageBounds():Rectangle {
  37. return null;
  38. }
  39.  
  40. public function set backgroundImageBounds(value:Rectangle):void {
  41. }
  42.  
  43. public function get hasBackgroundImage():Boolean {
  44. return false;
  45. }
  46.  
  47. public function layoutBackgroundImage():void {
  48. }
  49.  
  50. override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
  51. var em:EdgeMetrics = borderMetrics;
  52. if (em.bottom > 1) {
  53. cbbg.height = em.bottom - 1;
  54. cbdiv.bottom = cbbg.height;
  55. cbbg.visible = cbdiv.visible = true;
  56. } else {
  57. cbbg.visible = cbdiv.visible = false;
  58. }
  59. super.updateDisplayList(unscaledWidth, unscaledHeight);
  60. }
  61.  
  62. private static var panels:Object = {};
  63.  
  64. private static function isPanel(parent:Object):Boolean {
  65. var s:String = getQualifiedClassName(parent);
  66. if (panels[s] == 1) {
  67. return true;
  68. }
  69. if (panels[s] == 0) {
  70. return false;
  71. }
  72. if (s == "mx.containers::Panel") {
  73. panels[s] == 1;
  74. return true;
  75. }
  76. var x:XML = describeType(parent);
  77. var xmllist:XMLList = x.extendsClass.(@type == "mx.containers::Panel");
  78. if (xmllist.length() == 0) {
  79. panels[s] = 0;
  80. return false;
  81. }
  82. panels[s] = 1;
  83. return true;
  84. }
  85. ]]>
  86. fx:Script>
  87.  
  88. <s:Rect left="0" top="0" right="0" bottom="0">
  89. <s:filters>
  90. <s:DropShadowFilter blurX="20" blurY="20" alpha="0.32" distance="11" angle="90" knockout="true" />
  91. s:filters>
  92. <s:fill>
  93. <s:SolidColor color="0" />
  94. s:fill>
  95. s:Rect>
  96.  
  97. <s:Rect left="0" right="0" top="0" bottom="0">
  98. <s:stroke>
  99. <s:SolidColorStroke color="0" alpha="0.50" weight="1" />
  100. s:stroke>
  101. s:Rect>
  102.  
  103. <s:Rect id="background" left="1" top="1" right="1" bottom="1" alpha="0.6">
  104. <s:fill>
  105. <s:BitmapFill source="@Embed('assets/pattern_158.gif')" />
  106. s:fill>
  107. s:Rect>
  108.  
  109. <s:Rect left="1" right="1" top="1" height="30">
  110. <s:fill>
  111. <s:LinearGradient rotation="90">
  112. <s:GradientEntry color="0xE2E2E2" />
  113. <s:GradientEntry color="0xD9D9D9" />
  114. s:LinearGradient>
  115. s:fill>
  116. s:Rect>
  117.  
  118. <s:Rect left="1" right="1" top="1" height="30">
  119. <s:stroke>
  120. <s:LinearGradientStroke rotation="90" weight="1">
  121. <s:GradientEntry color="0xEAEAEA" />
  122. <s:GradientEntry color="0xD9D9D9" />
  123. s:LinearGradientStroke>
  124. s:stroke>
  125. s:Rect>
  126. <s:Rect left="1" right="1" top="31" height="1">
  127. <s:fill>
  128. <s:SolidColor color="0xC0C0C0" />
  129. s:fill>
  130. s:Rect>
  131.  
  132. <s:Rect id="cbbg" left="1" right="1" bottom="1" height="20">
  133. <s:fill>
  134. <s:SolidColor color="0xE8E8E8" />
  135. s:fill>
  136. s:Rect>
  137.  
  138. <s:Rect id="cbdiv" left="1" right="1" bottom="20" height="1">
  139. <s:fill>
  140. <s:SolidColor color="0xCDCDCD" />
  141. s:fill>
  142. s:Rect>
  143.  
  144. s:SparkSkin>

效果如下:

flex中如何设置Alert背景图片的例子_第1张图片