1

ステージ上に動的に配置されたインスタンスで hitTestObject を実行しようとしています。

エラーを受け取る:

TypeError: Error #2007: Parameter hitTestObject must be non-null.
    at flash.display::DisplayObject/_hitTest()
    at flash.display::DisplayObject/hitTestObject()
    at eatCircle()

アクションスクリプト:

    var circ; 
    var circle_ary:Array = new Array;   
    var circ_num:int;//number of circles on the stage

   // function with hitTestObject not working ---------------------------------
    function eatCircle(event:Event):void {
        if (player_ary[me].hitTestObject(circle_ary[circ])) { // does not work
                trace ("I ate the circle");
                removeChild(circle_ary[circ]); // does not work
            } else {
                trace ("I didn't eat the circle");
            }
    }        

// creates instances of the Circle class and are randomly placed on the stage
    var circ_num:int=5;//number of circles on the stage

                for(var i=0; i<circ_num; i++) {
                    circle_ary[i] = new Circle(); //linkage in the library
                    addChild(circle_ary[i]);

                    circle_ary[i].x = Math.random() * (stage.stageWidth -circle_ary[i].width);
                    circle_ary[i].y = Math.random() * (stage.stageHeight -circle_ary[i].height);
                }
4

1 に答える 1

1

前に言ったように、あなたはまた同じ間違いを犯しています。代わりに次のスニペットを使用してください。

 function eatCircle(event:Event):void {
        if((player_ary[me]!=null)&&(circle_ary[circ]!=null)&&(player_ary[me].hitTestObject(circle_ary[circ]))) {
                trace ("I ate the circle");
                removeChild(circle_ary[circ]);
            } else {
                trace ("I didn't eat the circle");
            }
    } 
于 2010-09-11T20:55:54.240 に答える