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

how to set a condition to apply to multiole frames

Explorer ,
Oct 05, 2024 Oct 05, 2024

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  😞

Views

187

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 , Oct 05, 2024 Oct 05, 2024

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;
...

Votes

Translate

Translate
Community Expert ,
Oct 05, 2024 Oct 05, 2024

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

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
Explorer ,
Oct 05, 2024 Oct 05, 2024

Copy link to clipboard

Copied

LATEST

THANK YOU SO MUCH!!

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