常见触发动画效果方式:
部分示例:
1:glow(发光)
代码:
<mx:Glow id="glow" duration="1000"
duratuion 是特效的时间 1000 毫秒
alphaFrom 是透明度从 0.6 开始
alphaTo 是透明度到 0.2
blurXFrom 是X放向的模糊开始位置(相对于控件的)
blurXTo 是X放向的模糊结束位置(相对于控件的)
blurYFrom 是Y放向的模糊开始位置(相对于控件的)
blurYTo 是Y放向的模糊结束位置(相对于控件的)
color 是发光的颜色
2:Sequence (顺序) Bounce(弹跳)
代码:
import mx.effects.easing.*;
<mx:Sequence id="movePauseMove">
yBy 是作用在Y方向。
duratuion 是特效的时间 1000 毫秒
easingFunction 是松开动作
Bounce.easeOut 是跳出的动作
Bounce.easeIn 是跳回的动作
作用到控件:
<mx:Image source="../assets/zh_cn_ptn_090722.png"
mouseDownEffect="{movePauseMove}"
id="image4"/>
自定义效果:
public class TestEffect extends Effect
{
public var alp:Number;
public var col:uint;
public function TestEffect(target:Object=null)
{
super(target);
instanceClass = TestInstance;
}
override protected function initInstance(instance:IEffectInstance):void{
super.initInstance(instance);
TestInstance(instance).col = this.col;
TestInstance(instance).alp = this.alp;
}
}
public class TestInstance extends EffectInstance
{
public var alp:Number;
public var col:uint;
public function TestInstance(target:Object)
{
super(target);
}
override public function play():void{
super.play();
(target as DisplayObject).alpha = this.alp;
var shape:FlexShape = new FlexShape();
shape.graphics.beginFill(col,1.0);
shape.graphics.drawRect(0,0,(target as DisplayObject).width,(target as DisplayObject).height);
shape.graphics.endFill();
var uiComp:UIComponent = new UIComponent();
uiComp.addChild(shape);
UIComponent(target).addChild(uiComp);
}
}
public class TestEffect extends Effect
{
public var alp:Number;
public var col:uint;
public function TestEffect(target:Object=null)
{
super(target);
instanceClass = TestInstance;
}
override protected function initInstance(instance:IEffectInstance):void{
super.initInstance(instance);
TestInstance(instance).col = this.col;
TestInstance(instance).alp = this.alp;
}
}
public class TestInstance extends EffectInstance
{
public var alp:Number;
public var col:uint;
public function TestInstance(target:Object)
{
super(target);
}
override public function play():void{
super.play();
(target as DisplayObject).alpha = this.alp;
var shape:FlexShape = new FlexShape();
shape.graphics.beginFill(col,1.0);
shape.graphics.drawRect(0,0,(target as DisplayObject).width,(target as DisplayObject).height);
shape.graphics.endFill();
var uiComp:UIComponent = new UIComponent();
uiComp.addChild(shape);
UIComponent(target).addChild(uiComp);
}
}
Sequence.addChild(move);
Sequence.addChild(glow);