forked from: flash on 2012-5-4

by bradsedito forked from flash on 2012-5-4 (diff: 3)
♥0 | Line 82 | Modified 2012-05-05 12:18:19 | MIT License
play

ActionScript3 source code

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

// forked from gogo178's flash on 2012-5-4
package {
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    public class Main extends Sprite
    {
        private var bone:Bone;
        private var circleA:Circle;
        private var circleB:Circle;
        
        public function Main ()
        {
            // write as3 code here..
            
            circleA = new Circle(0xFF0000);
            circleA.x = stage.stageWidth * 0.5;
            circleA.y = stage.stageHeight * 0.5;
            addChild(circleA);
            
            circleB = new Circle(0x00FF00);
            addChild(circleB);
            
            bone = new Bone();
            bone.rotationX = 0;
            bone.x = stage.stageWidth * 0.5;
            bone.y = stage.stageHeight * 0.5;
            addChild(bone);
            
            addEventListener(Event.ENTER_FRAME, onEnterFrame);
            stage.addEventListener(MouseEvent.CLICK, onClick);
        }
        
        private function onEnterFrame (event:Event):void
        {
            var x:Number = circleB.x - circleA.x;
            var y:Number = circleB.y - circleA.y;
            var z:Number = circleB.z - circleA.z;
            var radians:Number;
            radians = Math.atan2(y, z);
            bone.rotationY = radians * (180 / Math.PI);
            radians = Math.atan2(y, x);
            bone.rotationZ = radians * (180 / Math.PI);
            bone.x = circleA.x;
            bone.y = circleA.y;
        }
        
        private function onClick (event:MouseEvent):void
        {
            if (mouseY > stage.stageHeight * 0.5) {
                circleB.z += 10;
            } else {
                circleB.z -= 10;
            }


        }

    }
}

import flash.display.Sprite;
import flash.events.MouseEvent;
class Circle extends Sprite
{
    public function Circle (color:int)
    {
        graphics.beginFill(color);
        graphics.drawCircle(0, 0, 30);
        graphics.endFill();
        addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
        addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
    }
    
    private function onMouseDown (event:MouseEvent):void
    {
        startDrag();
    }
    
    private function onMouseUp (event:MouseEvent):void
    {
        stopDrag();
    }
}

import flash.display.Sprite;
class Bone extends Sprite
{
    public function Bone ()
    {
        mouseEnabled = false;
        graphics.beginFill( 0x131413 );
        // graphics.drawCircle(0, 0, 100);        
        graphics.lineTo(15, -15);
        graphics.lineTo(100, 0);
        graphics.lineTo(15, 15);
        graphics.endFill();
    }
}