flex_对象动画;

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值