Flex 效果的封转
前言:一些特殊的效果没写的,比如执行多个效果。以后再慢慢弄... 还省去啦值的安全检查...?
?????????? 哦,在补充一点。 这里每个方法都返回的一个Effect.以前写了个是在事件处理中写的,但觉得这样不
?????????? 好,所以就修改成啦这种。 一些编程风格,有啥子不好,还望大家指出。我也是新手了
?
源码:
EffectUtil??
package? com.util
{??
?import flash.display.DisplayObject;
?import flash.geom.Point;
?import mx.controls.Alert;
?import mx.effects.Blur;
?import mx.effects.Dissolve;
?import mx.effects.Effect;
?import mx.effects.Fade;
?import mx.effects.Glow;
?import mx.effects.Iris;
?import mx.effects.Move;
?import mx.effects.Resize;
?import mx.effects.Rotate;
?import mx.effects.SoundEffect;
?import mx.effects.WipeDown;
?import mx.effects.WipeLeft;
?import mx.effects.WipeRight;
?import mx.effects.WipeUp;
?import mx.events.EffectEvent;
?
?import spark.effects.WipeDirection;
?
?/**
? * 效果封装类,封装各个效果。调用方法见具体方法{这里先舍去传入值的判断,以后添加}
? * @author Administrator
? */
?
?//----------------不同的方式来触发动画效果-----------------------
?//?
?//? AddedEffect ?????加入容器
?//? creationCompleteEffect???创建完成
?//? focusInEffect ?????获得键盘输入
?//? focusOutEffect ????失去键盘输入
?//? mouseUpEffect ?????鼠标按起
?//? mouseDownEffect ????鼠标按下
?//? moveEffect ?????被拖动
?//? resizeEffect ?????重新设定大小
?//? removedEffect ?????被移除
?//? rollOverEffect ????鼠标移到控件上
?//? rollOutEffect ?????鼠标移到控件外
?//? hideEffect???????????????????? 隐藏前一刻发生 ?????
?//? showEffect ?????显示时发生?
?//--------------------------
?
?public class EffectUtil??
?{??
??
??//--------------------------------------
??//? 构造器
??//--------------------------------------
??
??public function EffectUtil()??
??{?
???
??}??
??
??//--------------------------------------
??//? 静态公开外部访问方法
??//--------------------------------------
??
??/**
?? * SetMove ?????移动组件位置
?? * @param fromPoint ??起点
?? * @param toPoint???终点
?? * @param durationTime??? ?持续时间
?? * @param delayTime??? ??延迟时间
?? * @param finishFun???完成后执行的函数方法
?? */? ? ?
??public static function GetMove(fromPoint:Point, toPoint:Point, durationTime:Number = 1000, delayTime:Number = 0, finishFun:Function = null):Effect
??{
???var move:Move = new Move ;?? //Move 效果在指定的时间间隔内随时间更改组件的位置
???
???move.xFrom = fromPoint.x;
???move.yFrom = fromPoint.y ;
???move.xTo = toPoint.x ;
???move.yTo = toPoint.y ;
???move.duration = durationTime ;??
???move.startDelay = delayTime ;??
???
???if(finishFun != null)??
????move.addEventListener(EffectEvent.EFFECT_END, finishFun) ;
???
???return move;
??}
??
??/**
?? * GetRotate? ????旋转效果
?? * @param durationTime??持续时间
?? * @param angleFrom???angleFrom
?? * @param angleTo???angleTo
?? * @param finishFun???完成后函数事件
?? * 调用示例:? mouseDownEffect="{EffectUtil.GetRotate()}" mouseUpEffect="{EffectUtil.GetRotate(555,360,0)}"
?? */??
??public static function GetRotate(durationTime:Number = 111, angleFrom:Number = 0, angleTo:Number = 360, finishFun:Function = null):Effect?
??{??
???var rotate:Rotate = new Rotate;?
???
???rotate.duration = durationTime;
???rotate.angleFrom = angleFrom;??
???rotate.angleTo = angleTo;??
???
???if(finishFun != null)??
????rotate.addEventListener(EffectEvent.EFFECT_END,finishFun);?
???
???return rotate;?
??}??
??
??/**
?? * SetResize? ????改变组件大小
?? * @param widthFrom???? ?初始宽度
?? * @param heightFrom??初始高度
?? * @param widthTo???最终宽度
?? * @param heightTo???最终高度
?? * @param durationTime??持续时间
?? * @param delayTime???延迟,以秒为单位
?? * @param finishFun???完成后执行的函数方法
?? * 调用示例:?? mouseDownEffect ="{EffectUtil.GetResize(btn.width,btn.height,btn.width *2,btn.height*2,2000)}"? mouseUpEffect="{EffectUtil.GetResize(btn.width,btn.height,btn.width/2,btn.height/2,3000)}"
?? */??
??public static function GetResize(widthFrom:Number =100,heightFrom:Number = 50,widthTo:Number =200,heightTo:Number = 100,durationTime:int = 1000,finishFun:Function = null):Effect?
??{??
???var resize:Resize = new Resize ;?? //改变组件大小
???
???resize.widthFrom = widthFrom ;??
???resize.heightFrom = heightFrom ;??
???resize.widthTo? = widthTo ;??
???resize.heightTo = heightTo ;
???resize.duration = durationTime ;??
???
???if(finishFun != null)??
????resize.addEventListener(EffectEvent.EFFECT_END, finishFun);??
???
???return resize;
??}??
??
??/**
?? * SetFade ????? 淡入,淡出效果
?? * @param delayTime??? ?? 延迟时间<秒为单位>
?? * @param durationTime ?? 持续时间
?? * @param alphaFrom? ?? alphaFrom
?? * @param alphaTo? ?? alphaTo
?? * @param finishFun?? ?? 完成后函数事件
?? * 调用示例:? rollOverEffect="{EffectUtil.GetFade()}" rollOutEffect="{EffectUtil.GetFade(0,1000,0,1)}"
?? */??
??public static function GetFade(delayTime:Number = 0,durationTime:Number = 1000,alphaFrom:Number = 1,alphaTo:Number = 0,finishFun:Function = null):Effect?
??{??
???var fade:Fade = new Fade ;? //淡入,淡出
???
???fade.startDelay = delayTime ;??
???fade.duration = durationTime;??
???fade.alphaFrom = alphaFrom;??
???fade.alphaTo = alphaTo;??
???
???if(finishFun !=null)??
????fade.addEventListener(EffectEvent.EFFECT_END,finishFun);??
???
???return fade;??
??}??
??
??/**
?? * SetBlur?? ????模糊效果
?? * @param durationTime???? 持续时间
?? * @param blurXFrom???blurXFrom
?? * @param blurXTo???blurXTo
?? * @param blurYFrom???blurYFrom
?? * @param blurYTo???blurYTo
?? * @param finishFun???完成后函数事件?
?? * 调用示例:? mouseDownEffect="{EffectUtil.GetBlur()}" mouseUpEffect="{EffectUtil.GetBlur(1000,10,0,10,0)}"
?? */??
??public static function GetBlur(durationTime:Number = 1000,blurXFrom:Number = 0,blurXTo:Number = 10,blurYFrom:Number = 0,blurYTo:Number = 10,finishFun:Function = null):Effect?
??{??
???var blur:Blur = new Blur ;??
???blur.duration = durationTime ;??
???blur.blurXFrom = blurXFrom ;??
???blur.blurXTo = blurXTo ;??
???blur.blurYFrom = blurYFrom ;??
???blur.blurYTo = blurYTo ;??
???
???if(finishFun != null)??
????blur.addEventListener(EffectEvent.EFFECT_END, finishFun) ;
???
???return blur;??
??}??
??
??/**
?? * GetGlow? ???发光效果
?? * @param color???颜色值
?? * @param alphaFrom???? alphaFrom?
?? * @param alphaTo??alphaTo
?? * @param blurXFrom??blurXFrom
?? * @param blurXTo??blurXTo
?? * @param blurYFrom??blurYFrom
?? * @param blurYTo??blurYTo
?? * @param durationTime?持续时间
?? * @param delayTime??延迟时间
?? * @param finishFun???? 效果完成后函数
?? * @return ????Effect
?? * 调用示例:rollOverEffect="{EffectUtil.GetGlow()}"?? rollOutEffect="{EffectUtil.GetGlow(0x000FF,0.3,1,50,0,50,0,2000,0)}
?? */??
??public static function GetGlow(color:Number = 0x0000FF,alphaFrom:Number = 1,alphaTo:Number = 0.5,blurXFrom:Number = 0,??
??????????? blurXTo:Number = 50,blurYFrom:Number = 0,blurYTo:Number = 50,durationTime:Number = 1000,delayTime:Number = 0,finishFun:Function = null):Effect?
??{??
???var glow:Glow = new Glow ;??
???glow.color = color ;??
???glow.alphaFrom = alphaFrom;??
???glow.alphaTo = alphaTo;??
???glow.blurXFrom = blurXFrom;??
???glow.blurXTo = blurXTo;??
???glow.blurYFrom = blurYFrom;??
???glow.blurYTo = blurYTo ;??
???glow.startDelay = delayTime ;?
???glow.duration = durationTime;
???
???if(finishFun != null)??
????glow.addEventListener(EffectEvent.EFFECT_END,finishFun) ;?
???
???return glow;??
??}??
??
??/**
?? * GetIris? Iris??? ??效果通过扩展或收缩集中在目标上的矩形蒙版为效果目标设置动画。该效果可以从目标的中心放大蒙版来显示目标,也可以向中心收缩蒙版来隐藏目标。
?? * @param durationTime??持续时间
?? * @param showTarget??指定如果为 true,则目标组件可见;如果为 false,则不可见。如果对 showEffect 或 hideEffect 触发器指定了此效果,则 Flex 会为您设置 showTarget 属性。
?? 当组件可见时设置为 true,当组件不可见时设置为 false。如果对其它效果触发器应用此效果,则需要自行设置此属性,通常在 startEffect 事件的事件侦听器中进行设置
?? * @param finishFun???效果完成后函数
?? * @return? Effect
?? */??
??public static function GetIris(durationTime:Number = 1000,showTarget:Boolean = true,finishFun:Function = null):Effect
??{
???var iris:Iris = new Iris();
???iris.duration = durationTime;
???iris.showTarget = true;
???
???if(finishFun != null)??
????iris.addEventListener(EffectEvent.EFFECT_END,finishFun) ;
???
???return iris;
??}
??
??/**
?? * GetDissolve????将组件的动画效果设置为从透明到不透明,或从不透明到透明
?? * @param durationTime ??持续时间
?? * @param alphaFrom???alphaFrom
?? * @param alphaTo???alphaFrom?
?? * @param finishFun???效果完成后函数
?? * @return??????? Effect
?? * 调用例子: hideEffect="{EffectUtil.GetDissolve()}" showEffect="{EffectUtil.GetDissolve(1000,0,1)}"
?? */??
??public static function GetDissolve(durationTime:Number = 1000,alphaFrom:Number = 1,alphaTo:Number = 0,finishFun:Function = null):Effect
??{
???var dissolve:Dissolve = new Dissolve();
???dissolve.duration = durationTime;
???dissolve.alphaFrom = alphaFrom;
???dissolve.alphaTo = alphaTo;
???
???if(finishFun != null)??
????dissolve.addEventListener(EffectEvent.EFFECT_END,finishFun) ;
???
???return dissolve;
??}
??
??/**
?? * GetWipe ?????擦拭效果? bug:这种是实现方法不太好
?? * @param effType???擦拭类型,目前只能为四种:WipeUp WipeDown WipeLeft WipeRight
?? * @param durationTime??持续时间?
?? * @param finishFun???效果完成后函数
?? * @return ?????Effect
?? * 示例 ??hideEffect="{EffectUtil.GetWipe('WipeLeft',555)}" showEffect="{EffectUtil.GetWipe('WipeRight',2000)}"
?? */??
??public static function GetWipe(effType:String = "WipeLeft",durationTime:Number = 1000,finishFun:Function = null):Effect
??{
???var effect:Effect = null;
???
???switch (effType.toLocaleLowerCase())
???{
????case "wipeup":
?????effect = new WipeUp();
?????break;
????case "wipedown":
?????effect = new WipeDown();
?????break;
????case "wipeleft":
?????effect = new WipeLeft();
?????break;
????case "wiperight":
?????effect = new WipeRight();
?????break;
????default:
?????Alert.show("调用效果类该方法<EffectUtil.GetWipe()>制定Wipe类型时,只能为:WipeUp,WipeDown,WipeLeft,WipeRight;你输入的是:" + effType);
???}
???
???effect.duration = durationTime;
???
???if(finishFun != null)??
????effect.addEventListener(EffectEvent.EFFECT_END,finishFun) ;
???
???return effect;
??}
??
??/**
?? * GetSound????????? 声音效果
?? * @param source???? 音频来源,Class格式。请从本项目中MusicUtil中提取
?? * @param finishFun? 效果完成后函数
?? * @return ??? Effect
?? */??
??public static function GetSound(source:Class,finishFun:Function = null):Effect
??{
???var soundEffect:SoundEffect = new SoundEffect();
???soundEffect.source = source;
???
???if(finishFun != null)??
????soundEffect.addEventListener(EffectEvent.EFFECT_END,finishFun) ;
???
???return soundEffect;
??}
?}??
}?
?
?
?MusicUtil
好像这个该取成资源的意思样...
?
package com.util
{
?/**
? * 音效资源类,支持mp3格式数据
? */
?public class MusicUtil
?{
??
??public function MusicUtil()
??{
???
??}
??
??/**
?? * Windows XP 惊叹号
?? */
??[Embed(source="../../assets/music/WindowsXP_whoa.mp3")]
??public static const whoa:Class;
??
??
??
?}
}
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?