Hi!
I’ve been seeing a lot of tutorials about hitTestObject and so i tried my own version of it(using their codes but having a different kind of approach ;)).
Its a basic click and drag type of “game” wherein you drag the objects on the left side to their proper match on the right side. I’ve been in circles with the error i’m getting:
‘Error #2007: Parameter hitTestObject must be non-null.’
The objects are already existing in the stage and i have imported and added the class file in the stage as well. The codes on work are on the as3 class file. Here’s the AS3 code:
package {
import flash.events.*;
import flash.ui.*;
import flash.display.*;
import com.greensock.TweenMax;
public class Main extends MovieClip {
public var tempX = 0;
public var tempY = 0;
public function Main():void {
buttonMode = true;
addEventListener(MouseEvent.MOUSE_DOWN, objStartDrag);
addEventListener(MouseEvent.MOUSE_UP, objStopDrag);
}
public function objStartDrag(event:MouseEvent):void {
Mouse.hide();
tempX = event.currentTarget.x;
tempY = event.currentTarget.y;
event.currentTarget.startDrag(true);
event.currentTarget.startAnimation(); /*starts the animation of the object that was selected*/
}
public function objStopDrag(event:MouseEvent):void {
trace("0");
if (event.target.hitTestObject(getChildByName(event.currentTarget.name + "Q")))
{
trace("correct answer");
// place constructors
}
else
{
trace("wrong answer");
TweenMax.to(event.currentTarget, .5,{x:tempX, y:tempY});
}
Mouse.show();
event.currentTarget.stopAnimation();
event.currentTarget.stopDrag();
}
}
}
Like i said, i’m going on circles with the error and also trying different ways not to make the object non-null. But no luck so far. Am i doing some kind of wrong approach on this? Thanks in advance.