=>animationApp.mxml
<?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"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:aspackage="aspackage.*"
minWidth="955" minHeight="600" pageTitle="TheStudioOfCenyebao">
<s:layout>
<s:VerticalLayout horizontalAlign="center" verticalAlign="middle"/>
</s:layout>
<fx:Script>
<![CDATA[
]]>
</fx:Script>
<fx:Declarations>
<!-- 非可视元素 -->
</fx:Declarations>
<s:VGroup width="320" height="230" horizontalAlign="center" verticalAlign="middle">
<aspackage:MyComponent id="myComponent"/>
</s:VGroup>
</s:Application>
=>MyComponent.as
package aspackage
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.utils.Timer;
import mx.core.UIComponent;
public class MyComponent extends UIComponent
{
/**
* 属性*/
/*圆*/
private var circle:Sprite;
/*计时器*/
private var myTimer:Timer;
/*是否已经单击*/
private var hasClick:Boolean=false;
/**
* 构造函数
*/
public function MyComponent()
{
/**
* 绘制圆*/
circle=new Sprite();
circle.graphics.beginFill(0x990000);
circle.graphics.drawCircle(50, 50, 50);
circle.graphics.endFill();
circle.useHandCursor=true;
circle.buttonMode=true;
this.addChild(circle);
/*圆_侦听单击事件*/
circle.addEventListener(MouseEvent.CLICK, startAnimationFn);
/*初始化计时器*/
myTimer=new Timer(2000, 1);
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerCompleteHandler);
}
/**
* 计时函数
* @param event
*/
private function onTimerCompleteHandler(event:TimerEvent):void
{
/**
* 再一次*/
circle.alpha=1;
hasClick=false;
}
/**
* 产生动画效果_圆逐渐模糊;
* @param event
*/
private function startAnimationFn(event:MouseEvent):void
{
if (myTimer.running)
{
myTimer.reset();
}
myTimer.start();
if (!hasClick)
{
circle.addEventListener(Event.ENTER_FRAME, fadeCircleFn);
hasClick=true;
}
}
/**
* 圆逐渐模糊
* @param event
* About_When this animation starts, this function is called every frame(每帧).
* The change made by this function (updated to the screen every frame) is what causes the animation to occur.
*/
private function fadeCircleFn(event:Event):void
{
/*通过改变圆的alpha值,来进行逐渐模糊效果*/
circle.alpha-=.05;
if (circle.alpha <= 0)
{
circle.removeEventListener(Event.ENTER_FRAME, fadeCircleFn);
}
}
}
}