forked from: flash on 2010-5-28

by yd_niku forked from flash on 2010-5-28 (diff: 67)
♥0 | Line 104 | Modified 2010-05-28 14:54:34 | MIT License
play

ActionScript3 source code

/**
 * Copyright yd_niku ( http://wonderfl.net/user/yd_niku )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/zCnp
 */

// forked from yd_niku's flash on 2010-5-28
package {
    import flash.display.Sprite;
    import flash.events.*;
    import flash.geom.*;
    import frocessing.display.*;
    public class FlashTest extends F5MovieClip2DBmp{
        public function FlashTest() {
            super();
            
        }
        private var n:int    = 2;
        private var t:Number = 0;
        public function setup():void{
            size( stage.stageWidth, stage.stageHeight);
            background(0);
            noFill();
            stroke( 255, 0.1 );
            
            var p:Sprite;
            
            p = new Ball(-200,232);
            _points.push(p);
            p = new Ball(-5,232);
            _points.push(p);
            
            for( var i:int=0; i<5; ++i){
                p = new Ball(100+70*i, Math.random()*200+130 );
                _points.push(p);
            }
            
            p = new Ball(470,232);
            _points.push(p);
            p = new Ball( 570,232);
            _points.push(p);
            
            for each( p in _points ) {
                addChild(p);    
            }
            _visible = true;
            
            stage.addEventListener(MouseEvent.CLICK,changeDebug);
        }
        private var _visible:Boolean;
        private function changeDebug(e:MouseEvent):void{
            _visible = !_visible;
            var p:Sprite;
            if(_visible){
            
                for each( p in _points ) {
                    addChild(p);    
                }    
            }
            else {
            
                for each( p in _points ) {
                    removeChild(p);    
                }    
                
            }
        }
        
        private var _points:Vector.<Sprite> = new Vector.<Sprite>();
        
        public function draw():void{
            var p:Sprite;
            
            background(0);
            beginShape();
            curveVertex( _points[0].x, _points[0].y );
            for each( p in _points ){
                curveVertex(p.x,p.y);
            }
            
            endShape();
            beginShape();
            
            curveVertex( _points[0].x, _points[0].y );
            for each( p in _points ){
                curveVertex(p.x+Math.sin(t)*3,p.y+Math.cos(t)*3);
            }
            
            endShape();
            
            var cnt:int=0;
            for each( p in _points ) {
                if( cnt%2 == 0 ) {
                    p.x += Math.cos(t)*0.1;
                    p.y += Math.sin(t)*0.5;
                }
                else{
                    p.x += -Math.cos(t)*0.1;
                    p.y += -Math.sin(t)*0.5;
                }
                cnt++;
            }
            
            t+=0.05;    
        }
        
    }
}

import flash.display.*;
import flash.events.*;
class Ball extends Sprite{
    public function Ball(sx:Number,sy:Number){
        graphics.beginFill(0xFFFFFF);
        graphics.drawCircle(0,0,4);
        graphics.endFill();
        
        x = sx;
        y = sy;
        addEventListener(MouseEvent.MOUSE_DOWN,mouseDown);
    }
    private function mouseDown(e:Event):void{
        startDrag();
        addEventListener(MouseEvent.MOUSE_UP,mouseUp);
        stage.addEventListener(MouseEvent.MOUSE_UP,mouseUp);
    }
    private function mouseUp(e:Event):void{
        stopDrag();
        
        removeEventListener(MouseEvent.MOUSE_UP,mouseUp);
        stage.removeEventListener(MouseEvent.MOUSE_UP,mouseUp);
    } 
    
}

Forked