function photoSlideOut(e:Event):void
{
e.target.parent.setChildIndex(e.target, e.target.parent.numChildren - 1);
Tweener.addTween(e.target, {x: photoDestX, time: speed, transition: easeType, onComplete:photoSlideIn, onCompleteParams:[e.target]});
Tweener.addTween(e.target, {rotation: Math.floor(Math.random()*(rotationRange*2))-rotationRange, time: speed*2, transition: easeType});
}
上面函数中第1句,是将被点击的照片移到最上层。
第1个参数:e.target是要应用补间的对象,这里是被点击的图片。
第2个参数:x是对象的属性,这里是对象的x属性,你可以改变对象的其它任何值。
第3个参数:photoDestX是这个属性值被改变后的值,这里是x被改变为photoDestX,即被点击的照片,x属性被改为向右移了200像素。
第4个参数:time是改变这个值需要的时间。
第5个参数:transition是缓动的类型。
第6个参数:onComplete是在这次补间完成时,要执行的的函数,这里在向移完成后,调用photoSlideIn函数,使照片移回原处。
第7个参数:onCompleteParams是传递给onComplete调用的函数的参数。这里将被点击的图片传给photoSlideIn函数。
总结下:Tweener的基本用法:
Tweener.addTween(要被应用补间的对象,{属性:变化后的值,time:所需时间});
上面函数第3句,再次应用Tweener,这次是产生一个从10到-10的旋转的补间动作。
接下来,是photoSlideIn函数:
function photoSlideIn(p:MovieClip)
{
p.parent.setChildIndex(p, 1);
Tweener.addTween(p, {x: photoOriginX, time: speed, transition: easeType});
}
这个函数,首先将照片的索引号设为1,放到了最下面一层,然后用Tweener将照片移回到原始位置。
接下来的两句比较简单:
for(var i=1; i<=photoCount; i++)
{
this["photo"+i].addEventListener(MouseEvent.MOUSE_DOWN, photoSlideOut);
this["photo"+i].rotation = Math.floor(Math.random()*(rotationRange*2))-rotationRange;
}
让所有图片侦听点击事件,调用photoSlideOut函数。
使所有图片产生一个从10到-10角度的旋转。
代码就这么多,快试试吧。
完整代码:
import caurina.transitions.*;
var photoOriginX:Number = photo1.x;
var photoDestX:Number = photoOriginX + 200;
var speed:Number = .5;
var rotationRange:Number = 10;
var photoCount:Number = 3;
var easeType:String = "easeoutquad";
function photoSlideOut(e:Event):void
{
e.target.parent.setChildIndex(e.target, e.target.parent.numChildren - 1);
Tweener.addTween(e.target, {x: photoDestX, time: speed, transition: easeType, onComplete:photoSlideIn, onCompleteParams:[e.target]});
Tweener.addTween(e.target, {rotation: Math.floor(Math.random()*(rotationRange*2))-rotationRange, time: speed*2, transition: easeType});
}
function photoSlideIn(p:MovieClip)
{
p.parent.setChildIndex(p, 1);
Tweener.addTween(p, {x: photoOriginX, time: speed, transition: easeType});
}
for(var i=1; i<=photoCount; i++)
{
this["photo"+i].addEventListener(MouseEvent.MOUSE_DOWN, photoSlideOut);
this["photo"+i].rotation = Math.floor(Math.random()*(rotationRange*2))-rotationRange;
}