<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
applicationComplete="init()">
<s:layout>
<s:VerticalLayout paddingLeft="20" paddingTop="20" />
</s:layout>
<fx:Script>
<![CDATA[
import flash.utils.Timer;
import spark.effects.animation.RepeatBehavior;
[Bindable]
protected var secondsTillDue:int = 5;
protected var _timer:Timer;
protected function init():void{
_timer = new Timer(1000); //tick every 1000ms 设置每1000ms运行一次的计时器
_timer.addEventListener('timer', onTimerTick);
_timer.start();
}
protected function onTimerTick(event:TimerEvent):void{
secondsTillDue = Math.max(secondsTillDue-1, 0);//更新secondsTillDue的值
if(secondsTillDue == 0){//如果secondsTillDue为0,那么播放效果并停止计时器
effect.play();
_timer.stop();
}
}
]]>
</fx:Script>
<fx:Declarations>
<s:GlowFilter id="filter" color="#de7800" blurX="20" blurY="20" />//设置GlowFilter来发出橘黄色的光
<s:AnimateFilter id="effect" target="{box}" bitmapFilter="{filter}"//AnimateFilter来播放效果
duration="1000" repeatCount="0"
repeatBehavior="{RepeatBehavior.REVERSE}">
<s:SimpleMotionPath property="alpha" valueFrom="0" valueTo="1" />//设置动画路径来创建alpha动画( RepeatBehavior常量REVERSE,LOOP创建往复效果)
</s:AnimateFilter>
</fx:Declarations>
<s:Label id="labelField" fontWeight="bold" fontSize="14"
text="Due in {secondsTillDue} seconds" />
<s:Rect id="box" width="200" height="200">
<s:fill>
<s:SolidColor color="black" />
</s:fill>
</s:Rect>
</s:Application>