Copy link to clipboard
Copied
Hi guys any help is greatly appreciated, what I'm trying to do is this ->
On button click, if the timeline is on frame 6, 12, 18 or 24, goto frame 54
If the timeline is on any other frame besides those ones, goto frame 73
I took a few guesses and tried to find the answer but no luck.
this.bulbut2.addEventListener("click", playjump.bind(this));
function playjump()
{
if (this.currentFrame == 6,12,18,24)
{
this.gotoAndPlay(54)
}
else ()
{
this.gotoAndPlay(73)
}
}
// I even ecrewed up the simple else condition 😞
Hi.
There are a few different ways you can do this. For example:
// Logical OR (||) operator
function playjump()
{
if (this.currentFrame === 6 || this.currentFrame === 12 || this.currentFrame === 18 || this.currentFrame === 24)
this.gotoAndPlay(54);
else
this.gotoAndPlay(73);
}
this.bulbut2.addEventListener("click", playjump.bind(this));
// Switch statement
function playjump()
{
switch(this.currentFrame)
{
case 6:
case 12:
case 18:
case 24:
this.gotoAndPlay(54);
break;
...
Copy link to clipboard
Copied
Hi.
There are a few different ways you can do this. For example:
// Logical OR (||) operator
function playjump()
{
if (this.currentFrame === 6 || this.currentFrame === 12 || this.currentFrame === 18 || this.currentFrame === 24)
this.gotoAndPlay(54);
else
this.gotoAndPlay(73);
}
this.bulbut2.addEventListener("click", playjump.bind(this));
// Switch statement
function playjump()
{
switch(this.currentFrame)
{
case 6:
case 12:
case 18:
case 24:
this.gotoAndPlay(54);
break;
default:
this.gotoAndPlay(73);
}
}
this.bulbut2.addEventListener("click", playjump.bind(this));
// Else if
function playjump()
{
if (this.currentFrame === 6)
this.gotoAndPlay(54);
else if (this.currentFrame === 12)
this.gotoAndPlay(54);
else if (this.currentFrame === 18)
this.gotoAndPlay(54);
else if (this.currentFrame === 24)
this.gotoAndPlay(54);
else
this.gotoAndPlay(73);
}
this.bulbut2.addEventListener("click", playjump.bind(this));
// Object literal
var targetFrames = { 6, 12, 18, 24 };
function playjump()
{
if (targetFrames[this.currentFrame] !== undefined)
this.gotoAndPlay(54);
else
this.gotoAndPlay(73);
}
this.bulbut2.addEventListener("click", playjump.bind(this));
// Object literal and ternary operator
var targetFrames = { 6, 12, 18, 24 };
function playjump()
{
this.gotoAndPlay(targetFrames[this.currentFrame] !== undefined ? 54 : 73);
}
this.bulbut2.addEventListener("click", playjump.bind(this));
// Array
var targetFrames = [ 6, 12, 18, 24 ];
function playjump()
{
if (targetFrames.indexOf(this.currentFrame) > -1)
this.gotoAndPlay(54);
else
this.gotoAndPlay(73);
}
this.bulbut2.addEventListener("click", playjump.bind(this));
// Array and ternary operator
var targetFrames = [ 6, 12, 18, 24 ];
function playjump()
{
this.gotoAndPlay(targetFrames.indexOf(this.currentFrame) > -1 ? 54 : 73);
}
this.bulbut2.addEventListener("click", playjump.bind(this));
I hope these help.
Regards,
JC
Copy link to clipboard
Copied
THANK YOU SO MUCH!!