这个类貌似是多余反正就是Tween类但是解决了动画可能播到半就停止了等问题Tween播放到半就停止了原因是类中侦听EnterFrame事件时候使用是弱引用侦听方式在播放途中被内存自动回收了因此播放到半就夭折了解决办法嘛除了自己写个也可以去包中改下Tween把侦听改成强引用就行了
我个人是不太习惯使用Tween因此我就写了这个类自己使用嘛大家觉得还不错就拿去用吧
缓动算法还是使用ADOBE自带那个easing包
这个类属性和思路方法比较多耐心看吧跟Tween差不了太多
类讲解:
index.base.animation.Motion类:
代码:public Motion extends EventDispatcher
提供给员使用动画类
构造:
public function Motion(target_:*,_attribute:String,_algorithm:Function,_begin:Number,_end:Number,_duration:u = 10)
和Tween模样只不过最后少了个属性是是否以时间计算缓动而该类只有以帧频计算缓动
play思路方法:
public function play:void
开始播放并触发播放事件
如果正在播放该思路方法不会有什么变化只不过会触发播放事件
back思路方法:
public function back:void
同于play思路方法区别是该思路方法是让动画反过来播放
resume思路方法:
public function resume:void
继续播放依然会触发播放事件
stop思路方法:
public function stop:void
停止播放触发停止事件
如果是播放完毕了即还会触发播放完毕事件
停止事件永远比播放完毕事件提前调度
re思路方法:
public function re:void
重置动画还原到刚开始例子化状态
无论是否正在播放都会触发停止事件
forward思路方法:
public function forward:void
快进到最后
rewind思路方法:
public function rewind:void
倒带到最前
next思路方法:
public function next:void
向前播放帧
如果是在播放中使用该思路方法效果不是太明显
prev思路方法:
public function prev:void
向前播放帧
如果是在播放中使用该思路方法效果不是太明显
clear思路方法:
public function clear:void
清除类中引用事件等
isBack属性(只读):
public function get isBack:Boolean
是否在回放状态
target属性(只读):
public function get target:*
获取当前操作对象
current属性(只读):
public function get current:u
获取当前播放位置
playing属性(只读):
public function get playing:Boolean
是否正在播放
attribute属性:
public var attribute:String;
设置操作对象属性没必要情况下最好不要修改
begin属性:
public var begin:Number;
设置操作对象属性没必要情况下最好不要修改
end属性:
public var end:Number;
设置操作对象结束属性没必要情况下最好不要修改
duration属性:
public var duration:u;
设置对象从值经过多少帧才运动到结束值
algorithm属性:
public var algorithm:Function;
设置对象从值到结束值是以什么算法进行运动
受保护属性:
protected var _current:u = 0;
protected function updata(isInit:Boolean = false):void
如果继承该类则可以访问_current属性和updata思路方法可以直接修改当前帧和强制更新屏幕
举例:(上面那个展示flash源代码)
对于各种区别算法进行效果展示小小偷了下懒使用flash自带组件
CODE:
import fl.transitions.easing.*;
import index.base.animation.Motion;
import index.base.events.MotionEvent;
//算法
var Ar:Array = [Back,Bounce,Elastic,None,Regular,Strong];
//小方块
var mc:MC = MC;
mc.y = 150;
addChild(mc);
//动画声明
var motion:Motion = Motion(mc,"x",Back.easeIn,50,350,40);
motion.addEventListener(MotionEvent.MOTION_UPDATA,motionUpdataFun);
motion.addEventListener(MotionEvent.MOTION_STOP,motionStopFun);
motion.addEventListener(MotionEvent.MOTION_PLAY,motionPlayFun);
motion.addEventListener(MotionEvent.MOTION_FINISH,motionFinishFun);
motion.play;
//动画播放完毕
function motionFinishFun(e:MotionEvent){
traceText.appendText("播放完毕
");
motion.isBack ? motion.play : motion.back;
traceText.scrollV = traceText.maxScrollV;
}
//屏幕更新
function motionUpdataFun(e:MotionEvent){
currentText.text = motion.current.toString;
traceText.appendText("屏幕更新当前帧 " + motion.current + "X属性:" + mc.x + "
");
traceText.scrollV = traceText.maxScrollV;
}
//动画播放
function motionPlayFun(e:MotionEvent){
traceText.appendText("开始播放
");
traceText.scrollV = traceText.maxScrollV;
}
//动画停止
function motionStopFun(e:MotionEvent){
traceText.appendText("停止播放
");
traceText.scrollV = traceText.maxScrollV;
}
//侦听各个面板change事件
List.addEventListener("change",changeFun);
funcList.addEventListener("change",changeFun);
durationBar.addEventListener("change",changeFun);
playButton.addEventListener("click",clickFun);
//当属性面板发生数值改变即触发
function changeFun(e:Event){
motion.rewind;
motion.algorithm = Ar[List.selectedItem.data][funcList.selectedItem.data];
motion.duration = durationBar.value;
durationText.text = durationBar.value.toString;
}
//播放按钮
function clickFun(e:Event){
(playButton.selected) motion.resume;
motion.stop;
}
//4个倒带前进等按钮事件
prevButton.addEventListener(MouseEvent.CLICK,function{motion.prev});
nextButton.addEventListener(MouseEvent.CLICK,function{motion.next});
forwardButton.addEventListener(MouseEvent.CLICK,function{motion.forward});
rewindButton.addEventListener(MouseEvent.CLICK,function{motion.rewind});
最新评论