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();
1 Correct answer
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
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
Copy link to clipboard
Copied
Such a rookie mistake of me. Now I can sleep tonight, haha thanks!
Copy link to clipboard
Copied
Don't worry! It's a common mistake! 😄
You're welcome!

