Copy link to clipboard
Copied
this is my code
var hits = 0;
tom.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
tom.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
function mouseDownHandler(evt:MouseEvent):void {
var object = evt.target;
// we should limit dragging to the area inside the canvas
object.startDrag();
}
function mouseUpHandler(evt:MouseEvent):void {
var obj = evt.target;
var target = obj.dropTarget;
if (target == food && obj == tom){
}
obj.visible=false;
{
}
}
else if (target != food && obj == tom)
{
obj.x=1051.05
obj.y=135.05
}
----------
!= imean by it:that if target doesn't equals food
if is that right,why this error appears?
Copy link to clipboard
Copied
Hi.
Your code has several formatting mistakes. The main one is that your else if statement is outside the function body.
I believe your code should be something like this :
var hits = 0;
tom.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
tom.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
function mouseDownHandler(evt:MouseEvent): void
{
var object = evt.target;
object.startDrag();
}
function mouseUpHandler(evt:MouseEvent): void
{
var obj = evt.target;
var target = obj.dropTarget;
if (target == food && obj == tom)
{
obj.visible = false;
}
else if (target != food && obj == tom)
{
obj.x = 1051.05;
obj.y = 135.05;
}
}
Please notice that I'm only looking at formatting and not functionality here.
Regards,
JC
Copy link to clipboard
Copied
Thank you for your effort
but (
obj.visible = false;
) doesn't work
Copy link to clipboard
Copied
hello,i had edited the code,now there is not a proplem with ( else ) but another proplem appeared.
( if ) condetion itself ,here is the code
var hits = 0;
tom.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
tom.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
function mouseDownHandler(evt:MouseEvent):void {
var object = evt.target;
// we should limit dragging to the area inside the canvas
object.startDrag();
}
function mouseUpHandler(evt:MouseEvent):void {
var obj = evt.target;
var target = obj.dropTarget;
if (target == food && obj == tom)
{
obj.visible=false;
}
else {
obj.x=1051.05;
obj.y=135.05;
obj.stopDrag();
}
}
the proplem is in this part
obj.visible=false;
it doesn't work
please i need a help
Copy link to clipboard
Copied
anybody there ????????