Mar 28
这个例子实际上和前面的Flex中格式化Slider控件的数据一样,除了实现的方法不一样以外,其效果上的差别只不过这个是带小数而且是多个的tips。这里主要是通过监听thumbPress和thumbRelease两个事件来记录是哪一个slider被滑动了。
另外需要注意的是,如果使用的是Flex Builder 3编译本例,那么有可能会因为类似下面的警告而无法创建发布程序:
Severity Description Resource In Folder Location Creation Time Id 1 Data binding will not be able to detect changes when using square bracket operator. For Array, please use ArrayCollection.getItemAt() instead. main.mxml main line 65 2008/03/28 1:06:18 98
先来让我们先来看一下Demo:
下面是完整代码:
Download: main.mxml
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
- layout="vertical"
- verticalAlign="middle"
- backgroundColor="white"
- applicationComplete="init();" >
- <mx:Script>
- <![CDATA[
- import mx.events.SliderEvent;
- private var thumbPrefixArray:Array;
- private var thumbIdx:int;
- /**
- * Initialize thumbPrefixArray with the two prefixes. There
- * needs to be enough items in the thumbPrefix array to
- * match the Slider's thumbCount property.
- */
- private function init():void {
- thumbPrefixArray = ["Minimum:", "Maximum:"];
- }
- /**
- * Formatter function for the dataTip.
- */
- private function formatDataTip(item:Number):String {
- // Set the data tip prefix based on the currently
- // selected thumb and get the prefix string from the
- // thumbPrefixArray array.
- var prefix:String = thumbPrefixArray[thumbIdx]
- return String(prefix + " $" + item.toFixed(2));
- }
- /**
- * Set/clear the thumbIdx variable depending on the
- * event that called this function. The thumbIdx variable
- * will be used to control the text that gets displayed in
- * the data tip.
- */
- private function setThumbIdx(evt:SliderEvent):void {
- switch (evt.type) {
- case SliderEvent.THUMB_PRESS:
- thumbIdx = evt.thumbIndex;
- break;
- case SliderEvent.THUMB_RELEASE:
- thumbIdx = undefined;
- break;
- }
- }
- ]]>
- </mx:Script>
- <mx:HSlider id="slider"
- thumbCount="2"
- values="[10, 90]"
- minimum="0"
- maximum="100"
- liveDragging="true"
- thumbPress="setThumbIdx(event);"
- thumbRelease="setThumbIdx(event);"
- dataTipFormatFunction="formatDataTip" />
- <mx:Label id="minimumLabel"
- text="Minimum: ${Number(slider.values[0]).toFixed(2)}" />
- <mx:Label id="maximumLabel"
- text="Maximum: ${Number(slider.values[1]).toFixed(2)}" />
- </mx:Application>
文中代码来自:flexexamples

March 28th, 2008 at 12:43 am
忘记了,代码也可以通过下面地址察看:
http://blog.minidx.com/ext/formatting-multiple-data-tips-in-a-slider/srcview/index.html