• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Syntax error: else is unexpected.in my code drag and drop

New Here ,
Oct 29, 2019 Oct 29, 2019

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?

TOPICS
ActionScript

Views

282

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
Community Expert ,
Oct 29, 2019 Oct 29, 2019

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

Votes

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
New Here ,
Oct 31, 2019 Oct 31, 2019

Copy link to clipboard

Copied

Thank you for your effort

but (

obj.visible = false;

) doesn't work 

Votes

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
New Here ,
Oct 31, 2019 Oct 31, 2019

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

Votes

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
New Here ,
Oct 31, 2019 Oct 31, 2019

Copy link to clipboard

Copied

LATEST

anybody there ????????

Votes

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