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

getObjectsUnderPoint動作確認

Get Adobe Flash player
by tepe 11 Mar 2012
    Embed
/**
 * Copyright tepe ( http://wonderfl.net/user/tepe )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/l9ie
 */

package {
    import flash.display.Sprite;
    import flash.geom.Point;
    import flash.text.*;
    import flash.events.*;
    
    public class FlashTest extends Sprite {
        private var container:Sprite = new Sprite();
        public function FlashTest() {
            
            var square1:Sprite = new Sprite();
            tf = new TextField();
            addChild(tf);
            tf.text = "aaa";
            tf.y = 0;
            square1.graphics.beginFill(0xFFCC00,0.5);
            square1.graphics.drawCircle(0,0,30);;

            var square2:Sprite = new Sprite();
            square2.graphics.beginFill(0x00CCFF,0.5);
            square2.graphics.drawRect(100, 50, 40, 40);
            
            var s3:Sprite = new Sprite();
            s3.graphics.beginFill(0x00CCFF,0.5);
            s3.graphics.drawRect(10, 0, 40, 40);

            container.addChild(square1);
            container.addChild(square2);
            container.addChild(s3);
            addChild(container);
            container.x = 100;
            container.y = 100;

            var pt:Point = new Point(10, 20);
            var objects:Array = container.getObjectsUnderPoint(pt); 
            tf.appendText("\n"+objects.length); // 1

            pt = new Point(35, 20);
            objects = container.getObjectsUnderPoint(pt);
            tf.appendText("\n"+objects.length);  // 2
            addEventListener(Event.ENTER_FRAME,onEnter);
        }
        
        
        private var tf:TextField;
        private function onEnter(e:Event):void{
            var pt:Point = new Point(mouseX,mouseY);
            var objects:Array = container.getObjectsUnderPoint(pt);
            tf.text = String(objects.length);
            for(var i:int=0;i<objects.length;i++){
                tf.appendText("\n"+objects[i].name);
            }

            
        }

        
    }
}