Highlighted

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

New Here ,
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

132

Likes

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

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

New Here ,
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

133

Likes

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
Oct 29, 2019 0
Adobe Community Professional ,
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

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

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
Reply
Loading...
Oct 29, 2019 2
New Here ,
Oct 31, 2019

Copy link to clipboard

Copied

Thank you for your effort

but (

obj.visible = false;

) doesn't work 

Likes

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
Reply
Loading...
Oct 31, 2019 0
New Here ,
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

Likes

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
Reply
Loading...
Oct 31, 2019 0
kattan LATEST
New Here ,
Oct 31, 2019

Copy link to clipboard

Copied

anybody there ????????

Likes

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
Reply
Loading...
Oct 31, 2019 0