Flex中如何通过swatchPanelStyleName和textFieldWidth样式调整ColorPicker的样本颜色数值表示框SIZE的例子

By Minidxer | January 25, 2009

接下来的例子演示了Flex中如何通过swatchPanelStyleName和textFieldWidth样式,调整ColorPicker的样本颜色数值表示框SIZE。

让我们先来看一下Demo可以右键View Source或点击这里察看源代码):


下面是完整代码(或点击这里察看):

Download: main.mxml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
  3.         layout="vertical"
  4.         verticalAlign="top"
  5.         backgroundColor="white">
  6.  
  7.     <mx:Script>
  8.         <![CDATA[
  9.             import mx.events.SliderEvent;
  10.  
  11.             private function slider_change(evt:SliderEvent):void {
  12.                 var cssObj:CSSStyleDeclaration = StyleManager.getStyleDeclaration(".myCustomSwatchPanelStyleName");
  13.                 cssObj.setStyle("textFieldWidth", evt.value);
  14.  
  15.                 colorPicker.open();
  16.             }
  17.         ]]>
  18.     </mx:Script>
  19.  
  20.     <mx:Style>
  21.         ColorPicker {
  22.             swatchPanelStyleName: myCustomSwatchPanelStyleName;
  23.         }
  24.  
  25.         .myCustomSwatchPanelStyleName {
  26.         }
  27.     </mx:Style>
  28.  
  29.     <mx:ApplicationControlBar dock="true">
  30.         <mx:Form styleName="plain">
  31.             <mx:FormItem label="textFieldWidth:">
  32.                 <mx:HSlider id="slider"
  33.                         minimum="0"
  34.                         maximum="172"
  35.                         value="72"
  36.                         snapInterval="1"
  37.                         tickInterval="5"
  38.                         liveDragging="true"
  39.                         dataTipPrecision="0"
  40.                         change="slider_change(event);" />
  41.             </mx:FormItem>
  42.         </mx:Form>
  43.     </mx:ApplicationControlBar>
  44.  
  45.     <mx:ColorPicker id="colorPicker" />
  46.  
  47. </mx:Application>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子

Topics: ColorPicker | No Comments » | 636 views Tags: , ,

Search Posts