1067: Implicit coercion of a value of type String to an unrelated type flash.display:DisplayObject.
Hi guys. I am building little games never anything too big. I'm having fun.
I'm getting the following error message
1067: Implicit coercion of a value of type String to an unrelated type flash.display:DisplayObject.
It's got to do with the varObject variable I pass into the hitTestObject (at the end of the code)
a. I exported the moveclip for actionscript and gave it an instance name so what's the problem???
stage.addEventListener(MouseEvent.CLICK, myClickReaction);
// speeds ALONG NYPOTENUSE
var v:Number=5;
var varObject:String;
var i:Number;
var arrayObjects:Array;
// populate array and initiate variables i and varObject
arrayObjects=["chocolate","icecream","pizza","hamburger","sandwich","egg"];
i = 1;
varObject = arrayObjects[i - 1];
trace(varObject);
// mouse click point
var clickPoint:Point = new Point();
function myClickReaction(e:MouseEvent):void {
clickPoint.x=mouseX;
clickPoint.y=mouseY;
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
function onEnterFrame(event:Event):void {
var xDistance:Number=clickPoint.x-sunny.x;
var yDistance:Number=clickPoint.y-sunny.y;
var angle:Number=Math.atan2(yDistance,xDistance);
sunny.x+=v*Math.cos(angle);
sunny.y+=v*Math.sin(angle);
if (clickPoint.x>=sunny.x) {
sunny.gotoAndPlay("walk right");
//trace(Math.abs(xDistance));
}
if (sunny.x>=clickPoint.x) {
sunny.gotoAndPlay("walk left");
//trace(Math.abs(xDistance));
}
if (Math.abs(xDistance)<=10) {
//trace("works");
sunny.gotoAndPlay("static");
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
}
}
addEventListener(Event.ENTER_FRAME,enterFrameHandler);
function enterFrameHandler(e:Event):void {
//if (sunny.hitTestObject(hotspot_pizza)) {
if (sunny.hitTestObject(varObject)) {
trace("Yeah boy");
}
}
