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

if statement ignored with onPressUp function

Participant ,
Nov 01, 2022 Nov 01, 2022

Copy link to clipboard

Copied

I don't get it. At the 'onPressUp' function I want the 'button2' movieclip to disappear and 'buttonAn' movieclip to play. But only if it is over the 650 y coordinate. I added the if statement but it is ignored.

 

Project file:

https://www.dropbox.com/s/mvpa1r73urwsvie/hide%20ball%20on%20drag%2008.fla?dl=0

 

var root = this;
this.button2.visible = false
this.buttonAn.visible = false

function main()
{
	createjs.Touch.enable(stage);
	root.mouseDownListener = root.button.on("mousedown", onMouseDown);
	root.pressMoveListener = root.button.on("pressmove", onPressMove);
	root.pressUpListener = root.button.on("pressup", onPressUp);
}

function onMouseDown(e)
{
	e.currentTarget.offset = { y: (e.stageY / stage.scaleY) - e.currentTarget.y };
}

function onPressMove(e)
{
	e.currentTarget.y = (e.stageY / stage.scaleY) - e.currentTarget.offset.y;
	{
	if (e.currentTarget.y > 650)
	root.button.visible = false
	root.buttonAn.visible = true
	}
}

function onPressUp(e)
{
	if (e.currentTarget.y > 650)
	root.button.y = 275
	root.fallingShape.play();
	root.button2.visible = true
	root.buttonAn.play();
}

main();

 

TOPICS
Code

Views

106

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

correct answers 1 Correct answer

Community Expert , Nov 01, 2022 Nov 01, 2022

Hi.

 

You're missing curly braces in the if statement. It should be like this:

 

 

 

function onPressUp(e)
{
	if (e.currentTarget.y > 650)
	{
		root.button.y = 275
		root.fallingShape.play();
		root.button2.visible = true
		root.buttonAn.play();
	}
}

 

 

 

If you don't use curly braces in a if statement, only the first line below it will be considered.

Regards,

JC

Votes

Translate

Translate
Community Expert ,
Nov 01, 2022 Nov 01, 2022

Copy link to clipboard

Copied

Hi.

 

You're missing curly braces in the if statement. It should be like this:

 

 

 

function onPressUp(e)
{
	if (e.currentTarget.y > 650)
	{
		root.button.y = 275
		root.fallingShape.play();
		root.button2.visible = true
		root.buttonAn.play();
	}
}

 

 

 

If you don't use curly braces in a if statement, only the first line below it will be considered.

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
Participant ,
Nov 01, 2022 Nov 01, 2022

Copy link to clipboard

Copied

Such a rookie mistake of me. Now I can sleep tonight, haha thanks!

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
Community Expert ,
Nov 01, 2022 Nov 01, 2022

Copy link to clipboard

Copied

LATEST

Don't worry! It's a common mistake! 😄

 

You're welcome!

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