Flex中如何通过自定义duration和easing函数使用户点击HSlider或VSlider滑轮时产生特定效果的例子

By Minidxer | September 14, 2008

接下来的例子演示了Flex中如何通过自定义duration和easing函数,使用户点击HSlider或VSlider滑轮时产生特定效果。

让我们先来看一下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="middle"
  5.         backgroundColor="white"
  6.         creationComplete="init();">
  7.  
  8.     <mx:Script>
  9.         <![CDATA[
  10.             import mx.events.ListEvent;
  11.             import mx.events.NumericStepperEvent;
  12.             import mx.effects.easing.*;
  13.  
  14.             private var arr:Array;
  15.  
  16.             private function init():void {
  17.                 arr = new Array();
  18.                 arr.push({label:"Elastic.easeInOut", func:Elastic.easeInOut});
  19.                 arr.push({label:"Bounce.easeOut", func:Bounce.easeOut});
  20.                 arr.push({label:"Back.easeIn", func:Back.easeIn});
  21.  
  22.                 easingFunc.dataProvider = arr;
  23.             }
  24.  
  25.             private function duration_change(evt:NumericStepperEvent):void {
  26.                 slider.setStyle("slideDuration", evt.value);
  27.             }
  28.  
  29.             private function easingFunc_change(evt:ListEvent):void {
  30.                 slider.setStyle("slideEasingFunction", easingFunc.selectedItem.func);
  31.             }
  32.         ]]>
  33.     </mx:Script>
  34.  
  35.     <mx:ApplicationControlBar dock="true">
  36.         <mx:Label text="slideDuration:" />
  37.         <mx:NumericStepper id="duration"
  38.                 minimum="0"
  39.                 maximum="2000"
  40.                 value="300"
  41.                 stepSize="100"
  42.                 change="duration_change(event);" /> 
  43.  
  44.         <mx:Label text="slideEasingFunction:" />
  45.         <mx:ComboBox id="easingFunc"
  46.                 change="easingFunc_change(event);"
  47.                 prompt="Please select an easing function..." />
  48.     </mx:ApplicationControlBar>
  49.  
  50.     <mx:HSlider id="slider" showTrackHighlight="true" tickInterval="1" />
  51.  
  52. </mx:Application>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子

Topics: Flex | Tags: , , , , ,

Related Post

Leave a Comment

Name(*):

E-Mail(*) :

Website :

Comments :

Search Posts

Archives

Sponsored Ads