|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
ActionScript是一种程序语言的简单文本文件.FLA档案能够直接包含ActionScript。
poluoluo中心提醒:本教程是利用FlashCS4大概FlexBuilder3内里的Actionscript3.0完成的一种十分大度的曲线殊效!
本教程是利用FlashCS4大概FlexBuilder3内里的Actionscript3.0完成的一种十分大度的曲线殊效!
最后的效果:
[media=wmv,545,396][/media]
上面大抵先容下制造的流程,文章的最初供应源码下载。个中的一些英文没有给人人翻译啊!呵呵
创建一个ActionScript3.0项目大概类
假如你用的是FlexBuilder那末你就创立一个新的ActionScript3.0项目,定名为LineEffect。假如你利用的是FlashCS3orCS4创立一个新的文档(ActionScript3.0)定名为LineEffect.as。
package{
importflash.display.Sprite;
SameImports
Again,ifyouuseFlexBuilder(FlexBuilderIusetoo),itisnotmandatorytowritethisstep,becauseFlexBuilderautomaticallyimportswhenitseessomethingunknown.ButifyouuseFlashCS3orCS4isrequiredtowritethisstep.- importflash.display.Graphics;importflash.display.MovieClip;importflash.display.Sprite;importflash.events.Event;importflash.events.MouseEvent;importflash.filters.BlurFilter;importflash.filters.DropShadowFilter;importflash.filters.GlowFilter;importflash.text.TextField;importflash.utils.getTimer;[SWF(width="600",height="400",frameRate="30",backgroundColor="#000000",pageTitle="LineEffect")]
复制代码 Ifyouareconfusedaboutthislineofcode:- [SWF(width="600",height="400",frameRate="30",backgroundColor="#000000",pageTitle="LineEffect")]
复制代码 Well,herewesetthewidth,height,framerate,backgroundColorandthetitleoftheSWFfile.
DeclaringVariables
Tobeeasierforyourfuturereference,I’vedeclaredvariablesforeachcolorline.ButbeforecolorsweneedtodeclareaSpritebecausewewanttodrawaline,andapplyaneffecttoit.AfterthatwewilldeclareanArraythatwillhelptoanimatetheline.Attheendwewilldeclarethebuttonswithtextasalsolinecolors.ThelinecolorsconsistsinaBlurFilter,twoGlowFilterandaDropShadowFilter.Thecodelookslikethat:- publicclassLineEffectextendsSprite{privatevarsp:Sprite=newSprite();privatevarpoints:Array=newArray();privatevarprevmouseX:Number=0;privatevarprevmouseY:Number=0;privatevarfireBtn:MovieClip=newMovieClip();privatevarfireTF:TextField=newTextField();privatevarskyBtn:MovieClip=newMovieClip();privatevarskyTF:TextField=newTextField();privatevargrassBtn:MovieClip=newMovieClip();privatevargrassTF:TextField=newTextField();privatevarsunBtn:MovieClip=newMovieClip();privatevarsunTF:TextField=newTextField();privatevarbf:BlurFilter=newBlurFilter(3,3,1);privatevargrowFilter:GlowFilter=newGlowFilter(0xff3300,2,20,10,2,3,true,false);privatevargrowFilter_b:GlowFilter=newGlowFilter(0xfff000,2,16,10,3,9,false,false);privatevardropShadow:DropShadowFilter=newDropShadowFilter(0,360,0xC11B17,1,70,70,5,3,false,false,false);privatevargrowFilter_2:GlowFilter=newGlowFilter(0x00ffff,2,20,10,2,3,true,false);privatevargrowFilter_b_2:GlowFilter=newGlowFilter(0x00ffff,2,16,10,3,9,false,false);privatevardropShadow_2:DropShadowFilter=newDropShadowFilter(0,360,0x000fff,1,70,70,5,3,false,false,false);privatevargrowFilter_3:GlowFilter=newGlowFilter(0x4AA02C,2,20,10,2,3,true,false);privatevargrowFilter_b_3:GlowFilter=newGlowFilter(0x4AA02C,2,16,10,3,9,false,false);privatevardropShadow_3:DropShadowFilter=newDropShadowFilter(0,360,0x4AA02C,1,70,70,5,3,false,false,false);privatevargrowFilter_4:GlowFilter=newGlowFilter(0xFDD017,2,20,10,2,3,true,false);privatevargrowFilter_b_4:GlowFilter=newGlowFilter(0xFDD017,2,16,10,3,9,false,false);privatevardropShadow_4:DropShadowFilter=newDropShadowFilter(0,360,0xFDD017,1,70,70,5,3,false,false,false);
复制代码 Whateventswehavehere?
Firstweaddthesp(Sprite)tothestage,thenweaddanEnter_FrameeventtoourSprite,draweachbuttonandcreateaClickeventforeachoneinordertochangefromcolorandeffect.- publicfunctionLineEffect(){this.addChild(sp);this.addEventListener(Event.ENTER_FRAME,onEnter);drawFireBtn(fireBtn);drawSkyBtn(skyBtn);drawGrassBtn(grassBtn);drawSunBtn(sunBtn);fireBtn.addEventListener(MouseEvent.CLICK,makeFire);skyBtn.addEventListener(MouseEvent.CLICK,makeSky);grassBtn.addEventListener(MouseEvent.CLICK,makeGrass);sunBtn.addEventListener(MouseEvent.CLICK,makeSun);sp.filters=[bf,dropShadow];}}}
复制代码 EnterFrameFunction
ThefollowingEnterFramefunctionwilltrackthemousecoordinatesandshowtheeffectonthestage.- privatefunctiononEnter(e:Event):void{varline:Graphics=sp.graphics;line.clear();line.lineStyle(2,0xffffff);line.moveTo(mouseX,mouseY);vardx:Number=this.mouseX-prevmouseX;varvx:Number=dx?dx:Math.random()*randSet(-1,1);vardy:Number=this.mouseY-prevmouseY;varvy:Number=dy?dy:Math.random()*randSet(-1,1);varpLen:Number=points.push({x:this.mouseX,y:this.mouseY,vx:vx/20,vy:vy/20,life:getTimer()});for(vari:Number=0;i<pLen;i++){if(!points[i]){continue}if(getTimer()-points[i].life>1000){points.splice(i--,1)}else{if(i!=0&&points[i]){points[i].x+=points[i].vx;points[i].y+=points[i].vy;varcx:Number=points[i-1].x;varcy:Number=points[i-1].y;line.curveTo(cx,cy,(points[i].x+cx)*0.5,(points[i].y+cy)*0.5);}else{line.moveTo(points[i].x,points[i].y);}}}prevmouseX=this.mouseX;prevmouseY=this.mouseY;}privatefunctionrandSet(p_min:Number,p_max:Number):Number{returnMath.floor(Math.random()*2);}}}
复制代码 Drawthebuttonsandmaketheclickevents
Nowwewriteafunctionforeachbuttonthatappliesthecolorsandeffectswehavecreatedinthebeginning.Oneachfunctionweinsertthetextbuttonsintothestagebydrawingitwithactionscript3.0usingthedrawRectclassandwechoosetherectanglefillcolor.ThenwecreateasecondfunctioninsidethisonewhichcallstheMouseEventwehavementionedaboveandwillstarttheeffect.- privatefunctiondrawFireBtn(obj:MovieClip):void{with(obj.graphics){beginFill(0x0000ff,0);drawRect(0,0,20,20);endFill();}fireTF.text="Fire"fireTF.textColor=0x666666;fireTF.mouseEnabled=false;fireTF.selectable=false;this.addChild(obj);obj.buttonMode=true;obj.addChild(fireTF);obj.x=20;obj.y=380;}privatefunctionmakeFire(E:MouseEvent):void{sp.filters=[bf,growFilter,growFilter_b,dropShadow];}privatefunctiondrawSkyBtn(obj:MovieClip):void{with(obj.graphics){beginFill(0x0000ff,0);drawRect(0,0,20,20);endFill();}skyTF.text="Sky"skyTF.textColor=0x666666;skyTF.mouseEnabled=false;skyTF.selectable=false;this.addChild(obj);obj.buttonMode=true;obj.addChild(skyTF);obj.x=70;obj.y=380;}privatefunctionmakeSky(e:MouseEvent):void{sp.filters=[bf,growFilter_2,growFilter_b_2,dropShadow_2];}privatefunctiondrawGrassBtn(obj:MovieClip):void{with(obj.graphics){beginFill(0x0000ff,0);drawRect(0,0,25,20);endFill();}grassTF.text="Grass"grassTF.textColor=0x666666;grassTF.mouseEnabled=false;grassTF.selectable=false;this.addChild(obj);obj.buttonMode=true;obj.addChild(grassTF);obj.x=120;obj.y=380;}privatefunctionmakeGrass(e:MouseEvent):void{sp.filters=[bf,growFilter_3,growFilter_b_3,dropShadow_3];}privatefunctiondrawSunBtn(obj:MovieClip):void{with(obj.graphics){beginFill(0x0000ff,0);drawRect(0,0,20,20);endFill();}sunTF.text="Sun"sunTF.textColor=0x666666;sunTF.mouseEnabled=false;sunTF.selectable=false;this.addChild(obj);obj.buttonMode=true;obj.addChild(sunTF);obj.x=170;obj.y=380;}privatefunctionmakeSun(e:MouseEvent):void{sp.filters=[bf,growFilter_4,growFilter_b_4,dropShadow_4];}}}
复制代码 ThiswastheLineEffecttutorial.Ihopeitwillbeusefullformanyofyou.Nowyoucantrytocreateyourownlineeffectsanddropacommentmentioningtheurlofyourexperiments.Wearealwayslookingfortheresultsofourtutorials.
源文件下载:http://www.webjx.com/files/soft/1_090619181757.zip
Flash8支持一种新的编码格式(On2的VP6),这种编码格式与Flash7的视频编码格式相比,有了很大的提高。 |
|