Flashas30实例教程100例分析和总结.docx
实例一 利用缓动类实现图片滚动点击放大效果
//缓动类不在flash包中在fl包中所以要先导入importfl.transitions.Tween;//导入缓动类
importfl.transitions.TweenEvent;//导入缓动事件
importfl.transitions.easing.Regular;//导入缓动效果中有规律的vararrTupian:Array=[];//存放图片的数组
vartweenscaleX:Tween;//用来控制图片宽高的缓动类vartweenscaleY:Tween;
vardatu:MovieClip;
for(vari:int=0;i8;i++){
varxiaotu:MovieClip=newPic();//这里Pic是库中一个存放图片的类文件addChild(xiaotu);
xiaotu.gotoAndStop(i+1);xiaotu.width=120;xiaotu.height=100;
xiaotu.x=xiaotu.width/2+i*(xiaotu.width+10);xiaotu.y=420;
arrTupian.push(xiaotu);
xiaotu.addEventListener(Event.ENTER_FRAME,dongf);//为每个小球添加移动帧频函数
}
functiondongf(e){
varmc:MovieClip=e.target;
mc.x-=6;
if(mc.x0-(xiaotu.width/2+10)){//如果该图片出了场景则放在最后一张图片的位置
mc.x=xiaotu.width/2+7*(xiaotu.width+10);
}
mc.buttonMode=true;
mc.addEventListener(MouseEvent.MOUSE_OVER,overf);///鼠标移过时候停止移动mc.addEventListener(MouseEvent.MOUSE_OUT,outf);//
}
functionoverf(e){
for(i=0;iarrTupian.length;i++){
//注意是点击一张图片应该让所有的图片都移除移动的侦听
arrTupian[i].removeEventListener(Event.ENTER_FRAME,dongf);arrTupian[i].removeEventListener(MouseEvent.MOUSE_OVER,overf);
//注意也要把移过函数移除,等下次再调用再添加防止下面的效果还没有达到又开始此函数
}
//此时大图出现
datu=newPic();datu.gotoAndStop(arrTupian.indexOf(e.target)+1);addChild(datu);
datu.x=stage.stageWidth/2;datu.y=200;
tweenscaleX=newTween(datu,scaleX,Regular.easeOut,1,3,0.5,true);//参数从1
倍扩大到3倍
tweenscaleY=newTween(datu,scaleY,Regular.easeOut,1,3,0.5,true);
//参数分别是对象,属性,缓动类型,开始参数,结束参数,缓动事件,true表示为单位为妙false表示为帧
}
functionoutf(e){
e.target.removeEventListener(MouseEvent.MOUSE_OVER,overf);e.target.removeEventListener(MouseEvent.MOUSE_OVER,outf);
tweenscaleX=newTween(datu,scaleX,Regular.easeOut,3,1,0.5,true);//开始和结
束的参数反过来则实现了缩小的效果
tweenscaleY=newTween(datu,scaleY,Regular.easeOut,3,1,0.5,true);
//tweenScaleX=newTween.yoyo()或者用这个方法,表示实现原来缓动的相反过程
//tweenScaleY=newTween.yoyo()
tweenscaleX.addEventListener(TweenEvent.MOTION_FINISH,fishf);
}
functionfishf(e){
removeChild(datu);
datu=null;//注意从显示列表中清除后,
//元件本身还有东西,因此还要把大图元件清空for