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

flash on 2010-8-8

ちょっとテスト...
@author narutohyper
Get Adobe Flash player
by narutohyper 09 Aug 2010
    Embed
/**
 * Copyright narutohyper ( http://wonderfl.net/user/narutohyper )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/cHR5
 */

package
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.geom.Point;
    import flash.events.MouseEvent;

    /**
     * ちょっとテスト...
     * @author narutohyper
     */
    public class Main extends Sprite {

        private var sA:DragCircle
        private var sB:DragCircle
        private var sC:DragCircle
        private var sP:DragCircle
        
        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


            //三角用の3つの点
            sA=new DragCircle(175,50,0x006600)
            sB=new DragCircle(50,200,0x006600)
            sC=new DragCircle(200,200,0x006600)
            //内包checkする点
            sP=new DragCircle(175,100,0xFF0000)
            addChild(sA);
            addChild(sB);
            addChild(sC);
            addChild(sP);
            stage.addEventListener(MouseEvent.MOUSE_MOVE,onMouseMove)
        }

        private function onMouseMove(e:MouseEvent):void {
            if (InDeltaCheck(sA.point,sB.point,sC.point,sP.point)) {
                sP.changeColor(0xFF0000)
            } else {
                sP.changeColor(0x0000FF)
            }
            graphics.clear()
            graphics.beginFill(0x00FF00,0.1)
            graphics.moveTo(sA.x, sA.y);
            graphics.lineTo(sB.x, sB.y);
            graphics.lineTo(sC.x, sC.y);
            graphics.lineTo(sA.x, sA.y);
        }

        private function distance($p1:Point,$p2:Point,$p3:Point):Number {
            var vX:Number=$p1.x -$p2.x;
            var vY:Number=$p1.y -$p2.y;
            return (vY*$p3.x-vX*$p3.y+vX*$p1.y-vY*$p1.x)/Math.sqrt(Math.pow(vX,2)+Math.pow(vY,2));
        }

        private function isSide($p1:Point,$p2:Point,$p3:Point,$p4:Point):Boolean {
            return ((distance($p1,$p2,$p3)*distance($p1,$p2,$p4)) >= 0);
        }

        private function InDeltaCheck($p1:Point,$p2:Point,$p3:Point,$p4:Point):Boolean {
            return isSide($p1,$p2,$p3,$p4) && isSide($p2,$p3,$p1,$p4) && isSide($p3,$p1,$p2,$p4)
        }
        

    }
    
}


import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.geom.Point;

class DragCircle extends Sprite {
    public static const MOVE:String="move";

    public function DragCircle($x:Number,$y:Number,$color:uint) {
        this.x=$x;
        this.y=$y;
        graphics.beginFill($color)
        graphics.drawCircle(0,0,5);
        this.addEventListener(MouseEvent.MOUSE_DOWN,onMouseDown)
    }

    private function onMouseDown(e:MouseEvent):void {
        stage.addEventListener(MouseEvent.MOUSE_MOVE,onMouseMove)
        stage.addEventListener(MouseEvent.MOUSE_UP,onMouseUp)
    }

    private function onMouseMove(e:MouseEvent):void {
        x=stage.mouseX
        y=stage.mouseY
    }

    private function onMouseUp(e:MouseEvent):void {
        stage.removeEventListener(MouseEvent.MOUSE_MOVE,onMouseMove)
        stage.removeEventListener(MouseEvent.MOUSE_UP,onMouseUp)
    }

    public function changeColor($color:uint):void {
        graphics.clear();
        graphics.beginFill($color);
        graphics.drawCircle(0,0,4);
    }

    public function get point():Point {
        return new Point(x,y);
    }


}