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

マウスカーソルによるBitmadDataのhitTest

実際には,マウスのx,y座標直下に(width,height)= (1,1)の正方形を用意して
マウスの動きに合わせて移動し,その物体とのチェックをしてる.
ぶっちゃけごまかし.でも動けば問題ない.今のところ
Get Adobe Flash player
by YAZUMA 22 Oct 2010
    Embed
//実際には,マウスのx,y座標直下に(width,height)= (1,1)の正方形を用意して
//マウスの動きに合わせて移動し,その物体とのチェックをしてる.
//ぶっちゃけごまかし.でも動けば問題ない.今のところ

package {
    import flash.text.TextFormat;
    import flash.text.TextField;
    import flash.events.MouseEvent;
    import flash.events.Event;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.geom.Point;
    [SWF(backgroundColor=0xffffff,width=500,height=400,frameRate=30)]
  
    public class FlashTest extends Sprite {
            private var bmp:Bitmap;
            private var bmp2:Bitmap;  
            private var test_bmpdata:BitmapData;
            private var tf:TextField = new TextField();
        public function FlashTest() {
            // write as3 code here..
            tf.defaultTextFormat = new TextFormat("Times New Loman", 24);
            tf.text = "out";
            tf.x = tf.y = 50;
            addChild(tf);
            test_bmpdata = new BitmapData(130, 130, true, 0x0);
            test_bmpdata.draw(new MOUSE(100, 100, 0x123456));
            bmp = new Bitmap(test_bmpdata);
            bmp.x = bmp.y = 150;
            addChild(bmp);
            var test_bmpdata2:BitmapData = new BitmapData(1, 1, true, 0x0);
            test_bmpdata2.draw(new MOUSE(1, 1, 0x987654));
            bmp2 = new Bitmap(test_bmpdata2); 
            bmp2.x = bmp2.y =  bmp2.alpha = 0;
            addChild(bmp2);
            bmp2.addEventListener(Event.ENTER_FRAME, Mouse_move_hand);
            addEventListener(Event.ENTER_FRAME, HITTEST);
        }
        private function Mouse_move_hand(e:Event):void{
            e.target.x = mouseX;
            e.target.y = mouseY;
        }
        private function HITTEST(e:Event):void{
            //tf.text ="check" ;
            if(test_bmpdata.hitTest(new Point(bmp.x, bmp.y), 255, bmp2, new Point(bmp2.x, bmp2.y), 255))
                 tf.text = "in";
            else tf.text = "out";

        }

    }
}
    import flash.display.Sprite;
class MOUSE extends Sprite{
    public function MOUSE(_w:int, _h:int, _color:int):void{
        graphics.beginFill(_color);
        graphics.drawRect(0, 0, _w, _h);
        graphics.endFill();
    }

}