Skip to main content
Known Participant
September 11, 2020
Question

buttonGetIcon return value

  • September 11, 2020
  • 2 replies
  • 1520 views

I have sifted thru posts, but can't find a solution ...

I want to execute a script from a button that will evaluate many image fields to determine if an image is assigned to the field.  The purpose is to clear a hidden text field of the original path of the imported icon in each. I have tried:

var isIcon = this.getField("Image17_af_image").value;

which returns "null"

var isIcon = this.getField("Image17_af_image").buttonGetIcon();

which returns [object Icon]

var isIcon = util.iconStreamFromIcon(this.getField("Image17_af_image").buttonGetIcon());

which returns [object Stream]

Is it possible to get a "Yes"/"No" response?

 

This topic has been closed for replies.

2 replies

try67
Community Expert
Community Expert
September 11, 2020

You can do it like this:

 

var buttonIcon = this.getField("Button3").buttonGetIcon();
try {
	var buttonIconStream = util.iconStreamFromIcon(buttonIcon);
	var streamLength = buttonIconStream.width*buttonIconStream.height;
	app.alert("Icon size: " + streamLength);
} catch (e) {
	app.alert("No icon found.");
}
Known Participant
September 11, 2020

Thanks try67! I'll be looking at "try" functionality.  Expect it will be very useful.

Code performing as needed:

var i = 0
for (var i=16;i<=112;i++)
if(i<70 || i>71){
{
s=i+"";
}
var buttonIcon = this.getField("Image"+s+"_af_image").buttonGetIcon();
try {
var buttonIconStream = util.iconStreamFromIcon(buttonIcon);
var streamLength = buttonIconStream.width*buttonIconStream.height;
// app.alert(streamLength);
}
catch (e) {
getField("FilePost"+s).value="";
getField("Text"+s).value="";
// app.alert("No icon found.");
}
}

 

try67
Community Expert
Community Expert
September 11, 2020

You can comment out the streamLength variable, too.

The try-catch clause is used to catch run-time errors and handle them properly (instead of just existing the code immediately). The iconStreamFromIcon method throws such an error when you use it on an empty Icon object.

Legend
September 11, 2020

Maybe the width and height of the icon object will give interesting info. Maybe not; perhaps there is always some kind of image assigned, even if it is blank.