flex的动画效果

<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
clipAndEnableScrolling="true"[color=red](动画显示控制在本区域范围内)[/color]
creationComplete="application1_creationCompleteHandler(event)">
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.events.EffectEvent;
import mx.events.FlexEvent;

import spark.effects.Animate;
import spark.effects.animation.MotionPath;
import spark.effects.animation.SimpleMotionPath;

private var _timer:Timer;

protected function application1_creationCompleteHandler(event:FlexEvent):void
{
// TODO Auto-generated method stub
animate.width = 100;
animate.height = 100;
animate.y = -this.height;[color=red](设置y坐标初始位置)[/color]
animate.x = 0;[color=red](设置x坐标初始位置)[/color]
}

protected function cb_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
var showMotionPath1:SimpleMotionPath = new SimpleMotionPath("y");
showMotionPath1.valueTo = this.height / 2;[color=red](路径1-y轴上的运动)[/color]
var showMotionPath2:SimpleMotionPath = new SimpleMotionPath("x");
showMotionPath2.valueTo = this.width / 2;[color=red](路径2-x轴上的运动)[/color]
var showMotionPaths:Vector.<MotionPath> = new Vector.<MotionPath>();
showMotionPaths.push(showMotionPath1);
showMotionPaths.push(showMotionPath2);[color=red](把两个路径放入vector集合中)[/color]
var showAnimate:spark.effects.Animate = new spark.effects.Animate();
showAnimate.target = animate;[color=red](动画对象)[/color] showAnimate.motionPaths = showMotionPaths;

showAnimate.duration = 1000;[color=red](动画执行的时长)[/color]
showAnimate.addEventListener(EffectEvent.EFFECT_END,showAnimate_effectEndHandler);[color=red](给动画加一个完成的监听事件)[/color]
showAnimate.play();[color=red](开始播放)[/color] }

private function showAnimate_effectEndHandler(event:EffectEvent):void
{
_timer = new Timer(3000,1);[color=red](完成上面的播放后3秒后执行timer事件1次)[/color]
_timer.addEventListener(TimerEvent.TIMER_COMPLETE,timer_timerCompleteHandler);
_timer.start();
}

private function timer_timerCompleteHandler(event:TimerEvent):void
{
var hiddenMotionPath:SimpleMotionPath = new SimpleMotionPath("y");
hiddenMotionPath.valueTo = -this.height;

var hiddenMotionPaths:Vector.<MotionPath> = new Vector.<MotionPath>();
hiddenMotionPaths.push(hiddenMotionPath);

var hiddenAnimate:spark.effects.Animate = new spark.effects.Animate();
hiddenAnimate.target = animate;
hiddenAnimate.motionPaths = hiddenMotionPaths;
hiddenAnimate.duration = 1000;

hiddenAnimate.play();

}
]]>
</fx:Script>
<s:Group id="animate" width="100" height="100">
<s:Rect top="0" bottom="0" left="0" right="">
<s:fill>
<s:SolidColor color="#BBBBBB"/>
</s:fill>
</s:Rect>
<s:Label text="动画效果" color="#000000"/>
</s:Group>
<s:Button id="cb" x="325" y="169" label="看效果" click="cb_clickHandler(event)"/>
</s:Group>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值