Error #2007: Parameter hitTestObject must be non-null

New Here ,
Feb 22, 2021 Feb 22, 2021

Copy link to clipboard

Copied

Hi, im still really new to actionscript 3.0 and try to make a simple drag and drop picture puzzle game but this error keeps on coming.. i tested it in another file and the game works just fine but when I input it in a new scene in the original file.. where the game main menu, opening, etc is at, the error keeps on coming when I  drop the puzzle piece to the designated target.. what should I do?

 

stop();

var objectoriginalX:Number;
var objectoriginalY;Number;
import flash.display.DisplayObject;

Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;

puzzle1piece1.addEventListener(TouchEvent.TOUCH_BEGIN, fl_TouchBeginHandler);
puzzle1piece1.addEventListener(TouchEvent.TOUCH_END, fl_TouchEndHandler);

puzzle1piece2.addEventListener(TouchEvent.TOUCH_BEGIN, fl_TouchBeginHandler);
puzzle1piece2.addEventListener(TouchEvent.TOUCH_END, fl_TouchEndHandler);

puzzle1piece3.addEventListener(TouchEvent.TOUCH_BEGIN, fl_TouchBeginHandler);
puzzle1piece3.addEventListener(TouchEvent.TOUCH_END, fl_TouchEndHandler);

puzzle1piece4.addEventListener(TouchEvent.TOUCH_BEGIN, fl_TouchBeginHandler);
puzzle1piece4.addEventListener(TouchEvent.TOUCH_END, fl_TouchEndHandler);

puzzle1piece5.addEventListener(TouchEvent.TOUCH_BEGIN, fl_TouchBeginHandler);
puzzle1piece5.addEventListener(TouchEvent.TOUCH_END, fl_TouchEndHandler);

puzzle1piece6.addEventListener(TouchEvent.TOUCH_BEGIN, fl_TouchBeginHandler);
puzzle1piece6.addEventListener(TouchEvent.TOUCH_END, fl_TouchEndHandler);

puzzle1piece7.addEventListener(TouchEvent.TOUCH_BEGIN, fl_TouchBeginHandler);
puzzle1piece7.addEventListener(TouchEvent.TOUCH_END, fl_TouchEndHandler);

puzzle1piece8.addEventListener(TouchEvent.TOUCH_BEGIN, fl_TouchBeginHandler);
puzzle1piece8.addEventListener(TouchEvent.TOUCH_END, fl_TouchEndHandler);

var fl_DragBounds:Rectangle = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight);

function fl_TouchBeginHandler(event:TouchEvent):void
{
event.target.startTouchDrag(event.touchPointID, false, fl_DragBounds);
objectoriginalX = event.target.x;
objectoriginalY = event.target.y;

}

function fl_TouchEndHandler(event:TouchEvent):void
{
event.target.stopTouchDrag(event.touchPointID);
var matchingTargetName:String = event.target.name + "target";
var matchingTarget:DisplayObject = getChildByName(matchingTargetName);
if(event.target.dropTarget != null && event.target.hitTestObject(matchingTarget))
{
event.target.removeEventListener(TouchEvent.TOUCH_BEGIN, fl_TouchBeginHandler);
event.target.removeEventListener(TouchEvent.TOUCH_END, fl_TouchEndHandler);
event.target.x = matchingTarget.x;
event.target.y = matchingTarget.y;
}
if(
puzzle1piece1.x == puzzle1piece1target.x && puzzle1piece1.y == puzzle1piece1target.y &&
puzzle1piece2.x == puzzle1piece2target.x && puzzle1piece2.y == puzzle1piece2target.y &&
puzzle1piece3.x == puzzle1piece3target.x && puzzle1piece3.y == puzzle1piece3target.y &&
puzzle1piece4.x == puzzle1piece4target.x && puzzle1piece4.y == puzzle1piece4target.y &&
puzzle1piece5.x == puzzle1piece5target.x && puzzle1piece5.y == puzzle1piece5target.y &&
puzzle1piece6.x == puzzle1piece6target.x && puzzle1piece6.y == puzzle1piece6target.y &&
puzzle1piece7.x == puzzle1piece7target.x && puzzle1piece7.y == puzzle1piece7target.y &&
puzzle1piece8.x == puzzle1piece8target.x && puzzle1piece8.y == puzzle1piece8target.y
)
{
gotoAndPlay(2);
}
}

TOPICS
How to

Views

32

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Feb 22, 2021 Feb 22, 2021

Copy link to clipboard

Copied

you should click file>publish settings>swf and tick "permit debugging".  that way the line number with the error will be in the error message.

 

but because you only have one hitTestObject, you already know where the error is located:


if(event.target.dropTarget != null && event.target.hitTestObject(matchingTarget))

 

 

to debug that (and all errors in as3), use the trace() statement:

 


var matchingTargetName:String = event.target.name + "target";
var matchingTarget:DisplayObject = getChildByName(matchingTargetName);

trace(matchingTargetName,matchingTarget);

 

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines