In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

forked from: Electricity Lines

Get Adobe Flash player
by nukerito 25 Apr 2009
// forked from nukerito's Electricity Lines
package {
    import flash.display.Sprite;
    import flash.display.StageScaleMode;
    import flash.display.StageAlign;
    import flash.events.Event;
    import flash.filters.GlowFilter;
    import flash.utils.Timer;
    import flash.events.TimerEvent;
    
    [SWF(width="60",height="60",frameRate="30", backgroundColor="0x000")]
    public class FlashTest extends Sprite {
        
        private var lines_sp:Sprite = new Sprite();
        private var numLines:Number = 30;
        private var chaosIntensity:Number = 50;
        private var chaosWeigth:Number = 5;
        private var elementColor:uint = 0x09CEFF;
        private var glowColor:uint = 0xfff;
        private var glowFilter:GlowFilter = new GlowFilter(glowColor,1,30,1,2);
        
        //attraction
        private var attraction:Boolean = true;
        private var attractionX:Number = 60;
        private var attractionY:Number = 100;
        
        //white Particles
        private var whiteParticlesMaxSize:Number = 5;
        private var whiteParticlesMaxDistance:Number = 50;
        
        
        //THE TIMER
        private var timer:Timer = new Timer(50 , 0);
        
        
        
        
        public function FlashTest() {
            // write as3 code here..
            init();
        }
        
        public function init():void
        {
            //stage
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            
            //lines
            addChild(lines_sp);
            refreshLines();
            
            //lines glow
            lines_sp.filters = [glowFilter]
            
            //EnterFrame Listener
            //stage.addEventListener(Event.ENTER_FRAME , onEnterFrameFunc);
            
            //Timer
            timer.addEventListener(TimerEvent.TIMER , refreshLines);
            timer.start();
            
        }
        
        private function refreshLines(evt:TimerEvent = null):void
        {
            var posX:Number = stage.stageWidth / numLines;
            
            lines_sp.graphics.clear();
            lines_sp.graphics.lineStyle(Math.random() * chaosWeigth ,elementColor);
            lines_sp.graphics.moveTo(  0 , stage.stageHeight * 0.5 );
                
            for(var i:int=0; i<numLines; i++)
            {
                if( (attraction) && (mouseY > stage.stageHeight * 0.5 - attractionY) && (mouseY < stage.stageHeight * 0.5 + attractionY) && (posX * i > mouseX - attractionX) && (posX * i < mouseX + attractionX) && (Math.random() > 0.5))
                {
                    var newParticle:whiteParticle = new whiteParticle();
                    
                    lines_sp.graphics.lineTo( mouseX , mouseY);
                    lines_sp.graphics.lineStyle(0 ,0 );
                    //lines_sp.graphics.beginFill(0xffffff , 1);
                    //lines_sp.graphics.drawCircle(mouseX , mouseY , Math.random() * whiteParticlesMaxSize);
                    lines_sp.graphics.endFill();
                    
                    newParticle.x = mouseX;
                    newParticle.y = mouseY;
                    
                    newParticle.x = mouseX + (Math.random() * whiteParticlesMaxDistance + Math.random() * - whiteParticlesMaxDistance) ;
                    newParticle.y = mouseY + (Math.random() * whiteParticlesMaxDistance + Math.random() * - whiteParticlesMaxDistance) ;
                    addChild(newParticle);
                }
                else
                {
                    lines_sp.graphics.lineStyle(Math.random() * chaosWeigth ,elementColor);
                    lines_sp.graphics.lineTo( posX * i , (( Math.random() * chaosIntensity) + stage.stageHeight * 0.5 - chaosIntensity * 0.5 ));
                }
            }
            lines_sp.graphics.lineStyle(Math.random() * chaosWeigth ,elementColor);
            lines_sp.graphics.lineTo( stage.stageWidth  , stage.stageHeight * 0.5); 
        }
        
        private function onEnterFrameFunc(e:Event):void
        {
            refreshLines();
        }
    }
}

import flash.events.Event;
import flash.display.Sprite;

class whiteParticle extends Sprite
{
    
    
    public function whiteParticle()
    {
        init();
    }
    
    private function init():void
    {
        this.graphics.beginFill(0xffffff , 1);
        this.graphics.drawCircle(0,0,Math.random() * 15);
        this.graphics.endFill();
        
        this.scaleX = 0;
        this.scaleY = 0;
        this.addEventListener(Event.ENTER_FRAME , scaleUp);
    }
    
    private function scaleUp(evt:Event):void
    {
        evt.currentTarget.y += 5;
        //evt.currentTarget.alpha -= 0.2;
        evt.currentTarget.scaleX += 0.3;
        evt.currentTarget.scaleY += 0.3;
        if(evt.currentTarget.scaleX >= 1 || evt.currentTarget.scaleY >= 1 )
        {
             evt.currentTarget.removeEventListener(Event.ENTER_FRAME , scaleUp);
             evt.currentTarget.addEventListener(Event.ENTER_FRAME , scaleDown);
        }
    }
    
    private function scaleDown(evt:Event):void
    {
        evt.currentTarget.y += 5;
        //evt.currentTarget.alpha -= 0.2;
        evt.currentTarget.scaleX -= 0.1;
        evt.currentTarget.scaleY -= 0.1;
        if(evt.currentTarget.scaleX <= 0 || evt.currentTarget.scaleY <= 0)
        {
            evt.currentTarget.alpha = -1;
             evt.currentTarget.removeEventListener(Event.ENTER_FRAME , scaleDown);
        }
    }
    
}