Flex _ OBJECT animation;

Source: Internet
Author: User

=> 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 );
}
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.