<?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.AnimateFilter;
import spark.effects.animation.MotionPath;
import spark.effects.animation.RepeatBehavior;
import spark.effects.animation.SimpleMotionPath;
import spark.filters.GlowFilter;
[Bindable]
protected var secondsTillDue:int = 5;
protected var _timer:Timer;
protected var _effect:AnimateFilter;
protected function init():void{
var filter:GlowFilter = new GlowFilter(0xde7800, 1, 20, 20);//设置GlowFilter来发出橘黄色的光
_effect = new AnimateFilter(box, filter);//创建效果实例
_effect.duration = 1000;
_effect.repeatCount = 0;
_effect.repeatBehavior = RepeatBehavior.REVERSE;
_effect.motionPaths = new <MotionPath>[
new SimpleMotionPath("alpha", 0, 1)];//建立alpha动画的MotionPath
_timer = new Timer(1000); //tick every 1000ms
_timer.addEventListener('timer', onTimerTick);
_timer.start();
}//将计时器设为每1000ms运行1次
protected function onTimerTick(event:TimerEvent):void{
secondsTillDue = Math.max(secondsTillDue-1, 0);//更新secondsTillDue的值
if(secondsTillDue == 0){
_effect.play();
_timer.stop();
}
}
]]>
</fx:Script>
<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>