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

Push reaction

Over the shape to push it.
Get Adobe Flash player
by drusunlimited 22 Sep 2011
/**
 * Copyright drusunlimited ( http://wonderfl.net/user/drusunlimited )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/1PSu
 */

package {

    import flash.events.*;
    import flash.display.*;


    public class PushableGlobeMain extends MovieClip {
        
        private const GLOBE_WIDTH:int=100;
        private const GLOBE_HEIGHT:int=120;
        private const CORD_LENGTH:int=300;
    
        public function PushableGlobeMain(){
            var globe:MovieClip=new MovieClip();
            with(globe.graphics){
                beginFill(0x999999);
                drawEllipse(-GLOBE_WIDTH/2,CORD_LENGTH,GLOBE_WIDTH,GLOBE_HEIGHT);
                lineStyle(0,0xe2e2e2);
                moveTo(0,0);
                lineTo(0,CORD_LENGTH);
                endFill();
            }
            globe.x=stage.stageWidth/2;
            globe.y=stage.stageHeight-10;
            globe.rotation=180;
            addChild(globe);
            new PushableGlobe(globe);
        }
    }
    
}

import flash.display.*;
import flash.events.*;

internal class PushableGlobe extends MovieClip {

    private static const G : Number=-9.8;
    private var _deg : Number=0;
    private var _adeg : Number=3;
    private var _radius : Number;
    private var _obj : DisplayObject;

    public function PushableGlobe(obj : DisplayObject) {
        _obj=obj;
        _radius=Math.abs(mouseY);
        _deg=_obj.rotation;
        _obj.addEventListener(MouseEvent.MOUSE_OVER, over);
    }

    public function shove(sense : int) : void {
        _obj.addEventListener(Event.ENTER_FRAME, update);
        _adeg=Math.random() * 3 * sense;

    }


    private function over(e : MouseEvent) : void {
        var sense : int=_obj.mouseX>0 ? 1 : -1;
        shove(sense);
    }


    private function physics() : void {
        var a : Number=-(G / _radius) * Math.sin(_deg / 180.0 * Math.PI);
        _adeg+=(a / Math.PI) * 180.0;
        _adeg*=.9;
    }

    private function update(e : Event) : void {
        physics();
        _deg=(_deg + _adeg) % 360;
        _obj.rotation=_deg;
    }
}