Highlighted

Show a button based on which layers are visible (javascript)

Community Beginner ,
Sep 10, 2020

Copy link to clipboard

Copied

So I've got a "Game" I've made in Acrobat where the user clicks on certain buttons and a layer appears. I wanted to do a final "congratulations" thing at the end when they click on the finish button.

 

Basically If "Layer 20" and "Layer 11" (and some others that I haven't done yet) are visible and the rest are not then I want the button "Complete" to appear.

 

Otherwise I'd like it to reset the visibility of the layers to the default state.

 

This is as far as I've got:

function FindOCG(cName) { 
    var aOCGs = this.getOCGs(); 
    for(var i=0; aOCGs && i<aOCGs.length;i++) { 
        if(aOCGs[i].name == cName) return aOCGs[i]; 
    } 
    return null; 
}
if(FindOCG("Layer 20"&&"Layer 11").state=true) 
{
this.getField("Complete").display=display.visible;
}
Else
{
this.getField("Complete").display=display.hidden;
}

If 20 and 11 are visible it appears okay, but if they're not visible and I click the Finish button then those layers appear and so does the finish button.

 

Please can anyone help, I'm so stuck now.

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

In addition to Bernd's correct comment, the comparison opeator in JS is either "==" or "===". So change this line:

if (FindOCG("Layer 20"&&"Layer 11").state=true)

to:

if (FindOCG("Layer 20").state==true && FindOCG("Layer 11").state==true)

TOPICS
Acrobat SDK and JavaScript

Views

53

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

Show a button based on which layers are visible (javascript)

Community Beginner ,
Sep 10, 2020

Copy link to clipboard

Copied

So I've got a "Game" I've made in Acrobat where the user clicks on certain buttons and a layer appears. I wanted to do a final "congratulations" thing at the end when they click on the finish button.

 

Basically If "Layer 20" and "Layer 11" (and some others that I haven't done yet) are visible and the rest are not then I want the button "Complete" to appear.

 

Otherwise I'd like it to reset the visibility of the layers to the default state.

 

This is as far as I've got:

function FindOCG(cName) { 
    var aOCGs = this.getOCGs(); 
    for(var i=0; aOCGs && i<aOCGs.length;i++) { 
        if(aOCGs[i].name == cName) return aOCGs[i]; 
    } 
    return null; 
}
if(FindOCG("Layer 20"&&"Layer 11").state=true) 
{
this.getField("Complete").display=display.visible;
}
Else
{
this.getField("Complete").display=display.hidden;
}

If 20 and 11 are visible it appears okay, but if they're not visible and I click the Finish button then those layers appear and so does the finish button.

 

Please can anyone help, I'm so stuck now.

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

In addition to Bernd's correct comment, the comparison opeator in JS is either "==" or "===". So change this line:

if (FindOCG("Layer 20"&&"Layer 11").state=true)

to:

if (FindOCG("Layer 20").state==true && FindOCG("Layer 11").state==true)

TOPICS
Acrobat SDK and JavaScript

Views

54

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
Sep 10, 2020 0
Adobe Community Professional ,
Sep 10, 2020

Copy link to clipboard

Copied

Following is not possible:

FindOCG("Layer 20"&&"Layer 11")

 FindOCG accepts only one name.

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...
Sep 10, 2020 1
Community Beginner ,
Sep 10, 2020

Copy link to clipboard

Copied

Thank you, that is very good to know!

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...
Sep 10, 2020 0
Most Valuable Participant ,
Sep 10, 2020

Copy link to clipboard

Copied

In addition to Bernd's correct comment, the comparison opeator in JS is either "==" or "===". So change this line:

if (FindOCG("Layer 20"&&"Layer 11").state=true)

to:

if (FindOCG("Layer 20").state==true && FindOCG("Layer 11").state==true)

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...
Sep 10, 2020 1
Adobe Community Professional ,
Sep 10, 2020

Copy link to clipboard

Copied

Is "==true" necessary?

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...
Sep 10, 2020 0
try67 LATEST
Most Valuable Participant ,
Sep 10, 2020

Copy link to clipboard

Copied

No, it's not. I just left it because it was in the original code.

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...
Sep 10, 2020 0
Community Beginner ,
Sep 10, 2020

Copy link to clipboard

Copied

Thank you SO much! That work's perfectly!

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...
Sep 10, 2020 0