GLOW EFFECT VIA ACTIONSCRIPT as3 |
This tutorial will show you how to create and control basic glowing effects using only actionscript 3.0. At the end you should get something like the example below:
Open new actionscript 3.0 flash file and create or insert object you want to add the glowing effect to. Convert it to movieclip and name it start_mc, or use other name just make sure it matches the name used in actionscript.
Select first frame and insert following actionscript code:
stop(); var i:Number=0; stage.addEventListener(Event.ENTER_FRAME,glowUP); function glowUP(e:Event) { i++; var glow:GlowFilter = new GlowFilter(); glow.color=0xFF0000; glow.alpha=1; glow.blurX=i; glow.blurY=i; glow.quality=BitmapFilterQuality.HIGH; star_mc.filters=[glow]; if (i>50) { gotoAndStop(2); } }
Line 4 creates stage listener which runs the glowUP function every time frame loads. The function itself sets the parameters of glowing filter such as alpha, blurX and Y and quality. Then assignes
this GlowFilter to star_mc movieclip. When i variable reaches 50 it moves stage to frame 2. Insert this frame on timeline and copy the movieclip from previous frame on the same spot ( you can use shift+ctr+v ). Name this one
star2_mc. Open actions pannel for second frame and insert this actionscript code:
stop(); var j:Number=50; stage.addEventListener(Event.ENTER_FRAME,glowDOWN); function glowDOWN(e:Event){ j--; var glow1:GlowFilter = new GlowFilter(); glow1.color = 0xFF0000; glow1.alpha = 1; glow1.blurX = j; glow1.blurY = j; glow1.quality = BitmapFilterQuality.HIGH; star2_mc.filters = [glow1]; if(j<2){ gotoAndStop(1); } }
This function works exactly like script on previous frame with one difference. Instead of increasing the glow , this one is decreasing it. When j reaches 2, it moves stage to first frame creating infinite loop.
|