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

[test] Right Click

右クリックテスト
Get Adobe Flash player
by okoi 25 Sep 2012
/**
 * Copyright okoi ( http://wonderfl.net/user/okoi )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/4s1M
 */

package 
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    
    [SWF(width = "465", height = "465", frameRate = "60")]
    
    /**
     * 右クリックテスト
     * @author okoi
     */
    public class Main extends Sprite 
    {
        private var _particleList:Array/*Particle*/ = [];
        private var _isRightMouseDown:Boolean = false;
        
        public function Main():void 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }
        
        private function init(e:Event = null):void 
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            // entry point
            
            stage.addEventListener( MouseEvent.RIGHT_MOUSE_DOWN, _rightMouseDownHandler, false, 0, true );
            stage.addEventListener( MouseEvent.RIGHT_MOUSE_UP, _rightMouseUpHandler, false, 0, true );
            addEventListener( Event.ENTER_FRAME, _enterFrameHandler, false, 0, true );
        }
        
        private function _rightMouseUpHandler(e:MouseEvent):void 
        {
            _isRightMouseDown = false;
        }
        
        private function _rightMouseDownHandler(e:MouseEvent):void 
        {
            _isRightMouseDown = true;
        }
        
        private function _enterFrameHandler(e:Event):void 
        {

            this.graphics.clear();
            this.graphics.lineStyle(1, 0);
            var particleCount:int = _particleList.length;
            for ( var i:int = particleCount - 1; i >= 0; i-- ) {
                
                _particleList[i].x += _particleList[i].vx;
                _particleList[i].y += _particleList[i].vy;
                _particleList[i].life--;
                
                if ( _particleList[i].life <= 0 ) {
                    _particleList.splice( i, 1 );
                }else {
                    this.graphics.drawCircle( _particleList[i].x, _particleList[i].y, 2 );
                }
                
            }
            
            if ( _isRightMouseDown ) {
                _addParticle();
            }
        }
        
        private function _addParticle() : void
        {
            var particle:Particle = new Particle();
            particle.x = stage.mouseX;
            particle.y = stage.mouseY;
            particle.life = Math.random() * 100 + 100;
            particle.vx = Math.random() * 10 - 5;
            particle.vy = Math.random() * 10 - 5;
            
            _particleList.push( particle );
        }
    }
    
}

class Particle 
{
    public var x:Number;
    public var y:Number;
    public var life:int;
    public var vx:Number;
    public var vy:Number;
}