=> 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>
<! -- Non-visual element -->
</FX: declarations>
<S: vgroup width = "320" Height = "230" horizontalalign = "center" verticalalign = "Middle">
<Aspackage: mycomponent id = "mycomponent"/>
</S: vgroup>
</S: Application>
=> Mycomponent.
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
{
/**
* Attribute */
/* Circle */
Private var circle: SPRITE;
/* Timer */
Private var mytimer: timer;
/* Whether or not you have clicked */
Private var hasclick: Boolean = false;
/**
* Constructor
*/
Public Function mycomponent ()
{
/**
* Draw circles */
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 _ listen for click events */
Circle. addeventlistener (mouseevent. Click, startanimationfn );
/* Initialize the timer */
Mytimer = new timer (2000, 1 );
Mytimer. addeventlistener (timerevent. timer_complete, ontimercompletehandler );
}
/**
* Timing Functions
* @ Param event
*/
Private function ontimercompletehandler (Event: timerevent): void
{
/**
* Once again */
Circle. Alpha = 1;
Hasclick = false;
}
/**
* Produce animated effect _ gradually blur the circle;
* @ 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;
}
}
/**
* Gradually blur the circle
* @ Param event
* About_when this animation starts, this function is called every frame (per 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
{
/* Gradually blur the result by changing the Alpha value of the circle */
Circle. Alpha-=. 05;
If (circle. Alpha <= 0)
{
Circle. removeeventlistener (event. enter_frame, fadecirclefn );
}
}
}
}