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

Hit Test Ring

Get Adobe Flash player
by shapevent 09 Jan 2011
/**
 * Copyright shapevent ( http://wonderfl.net/user/shapevent )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/gEGA
 */

package {
    import flash.display.Sprite;
    import flash.events.Event;
    
    public class FlashTest extends Sprite {
        private var color:uint;
        
        public function FlashTest() {
            addEventListener(Event.ENTER_FRAME, onLoop);
        }
        private function onLoop(evt:Event):void{
        
          graphics.clear();    
          
          color = 0;
          
          var inner:Number = 100;
          var outer:Number = 200;
          var x:Number = stage.stageWidth / 2;
          var y:Number = stage.stageHeight / 2
          var distance:Number = dist(x, y, mouseX, mouseY);
          if (distance > inner && distance < outer){
            color = 0xFF0000;     
          }
         
          drawRing(x, y, outer, inner);
            
        }
        
        private function dist(x1:Number, y1:Number, x2:Number, y2:Number):Number{
          var dx:Number = x1 - x2;
          var dy:Number = y1 - y2;
          return Math.sqrt(dx * dx + dy * dy);    
        }
        
        private function drawRing(x:Number, y:Number, innerRadius:Number, outerRadius:Number):void{
          graphics.beginFill(color);
          graphics.drawCircle(x, y, outerRadius);
          graphics.drawCircle(x, y, innerRadius);
          graphics.endFill();
        }
    }
}