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

forked from: HitTestObject

Get Adobe Flash player
by bobby1 22 Jan 2013
    Embed
/**
 * Copyright bobby1 ( http://wonderfl.net/user/bobby1 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/2MPO
 */

// forked from bobby1's HitTestPoint
// forked from bobby1's 2次ベジェ
package {
    import flash.display.Stage;
    import flash.events.MouseEvent;
    import flash.geom.Rectangle;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.utils.Timer;
    import flash.text.TextField;
    import flash.display.Graphics;
    import flash.display.Shape;
    import flash.events.Event;
    import flash.geom.Point;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        

        private var tf:TextField = new TextField();
        private function makeDebugTF():void{
            tf.width = 200;
            tf.height = 200;
            tf.scaleX = tf.scaleY = 2;
            tf.text = "aaas";
            //tf.textColor = 0xffffffff;
            this.addChildAt(tf,0);
            tf.mouseEnabled = false;
        }

        
        private function onMouseEvent( e:MouseEvent ):void{
            
            tf.text = "local "+ shape.hitTestPoint( e.localX, e.localY, true );
            tf.text += "\nstage "+ shape.hitTestPoint( e.stageX, e.stageY, true );
            
        }


        private function createRect( color:uint = 0x0 ):Sprite {
            var s:Sprite = new Sprite();
            s.graphics.beginFill( color );
            s.graphics.drawRect( -40,-40,80,80 );
            return s;
        }


        private var r1:Sprite;
        private var r2:Sprite;
        private var r3:Sprite;
        private var r4:Sprite;
        private var r5:Sprite;
        
        public function FlashTest() {
            makeDebugTF();
            //addEventListener(Event.EXIT_FRAME, ef);
           
            r1 = addChild( createRect( 0xff0000 ) ) as Sprite;
            r2 = addChild( createRect( 0xff8000 ) ) as Sprite;
            r3 = addChild( createRect( 0xff0080 ) ) as Sprite;
            r4 = shape.addChild( createRect( 0x00ff80 ) ) as Sprite;
            r5 = addChild( createRect( 0x0080ff ) ) as Sprite;
            
            r1.x = r1.y = 100;
            r2.x = r2.y = 200;
            r3.x = r3.y = 300;
            r4.x = 100;r4.y = 300;
            r5.x = 100;r5.y = 300;
            
            addEventListener( Event.ENTER_FRAME, oef );
            
            
            addChild( shape );
            addChild( canvas );
            
            shape.scaleX = shape.scaleY = 1.2;
            shape.y = -65;
        }
        
        private var shape:Sprite = new Sprite();
        
        private var canvas:Shape = new Shape();
        
        private function oef(e:Event):void {
            r1.rotation+=0.5;
            r2.rotation+=0.8;
            r3.rotation+=1;
            r4.rotation+=1.2;
            r5.rotation+=1.2;
            
            var g:Graphics = canvas.graphics;
            g.clear();
            
            g.lineStyle(1,0xff0000);
            var r:Rectangle = r1.getBounds(canvas);
            g.drawRect(r.x,r.y,r.width,r.height);
            r = r2.getBounds(canvas);
            g.drawRect(r.x,r.y,r.width,r.height);
            r = r3.getBounds(canvas);
            g.drawRect(r.x,r.y,r.width,r.height);
            r = r4.getBounds(canvas);
            g.drawRect(r.x,r.y,r.width,r.height);
            r = r5.getBounds(canvas);
            g.drawRect(r.x,r.y,r.width,r.height);
            
            
            g.lineStyle( 5,0xffff00 );
            
            var stage:Stage = stage;
            stage.removeChild(this);
            
            var result: Boolean = r1.hitTestObject(r2);
            if( result ) {
                g.moveTo( r1.x, r1.y );
                g.lineTo( r2.x, r2.y );
            }
            
            result = r2.hitTestObject(r3);
            if( result ) {
                g.moveTo( r2.x, r2.y );
                g.lineTo( r3.x, r3.y );
            }
            
            
            shape.removeChild( r4 );
            result = r2.hitTestObject(r4);
            shape.addChild( r4 );
            if( result ) {
                g.moveTo( r2.x, r2.y );
                g.lineTo( r4.x, r4.y );
            }
            
            result = r1.hitTestObject(r2);
            if( result ) {
                g.moveTo( r1.x, r1.y );
                g.lineTo( r2.x, r2.y );
            }
            
            stage.addChild(this);
        }

        
        
        
        
        
    }
}