Expand my Community achievements bar.

Case statment stops working

Avatar

Level 3

I have a case statement that stops working. Which is very strange as it should work forever as far as I can tell.

My code is below and the symptoms are that clicking on the button chaages the image between 2 and 12 times but eventually stops responding.

//create arrays
var fmtIm_3d = Array("fmt_3d_0");
var fmtIm_aerial = Array("fmt_aerial_0");
var fmtIm_green = Array("fmt_green_0");
var fmtIm_heli = Array("fmt_heli_0");
var fmtIm_info = Array("fmt_info_0");
var fmtIm_interview = Array("fmt_interview_0");
var fmtIm_style = Array("fmt_style_0");
var fmtIm_time = Array("fmt_time_0");
var fmtIm_title = Array("fmt_title_0");

var allImages = Array(  fmtIm_3d  ,  fmtIm_aerial  ,  fmtIm_green  ,  fmtIm_heli  ,  fmtIm_info  ,  fmtIm_interview  ,  fmtIm_style  ,  fmtIm_time  ,  fmtIm_title  );

//get value from dropdown
var whichSelect = filmTitle.$.rawValue;

var imageName = allImages[whichSelect][0];
var imageName01 = imageName;

var integer01 = "1";
var integer02 = "2";
var integer03 = "3";
var integer04 = "4";

switch (fCounterA.value)
{
    case "1":
    fCounterA.value = "2";
    displayImage = imageName01 + integer01 + ".value.image.value";
    filmAImageField.rawValue = eval(displayImage);
    break;
   
    case "2":
    fCounterA.value = "3";
    displayImage = imageName01 + integer02 + ".value.image.value";
    filmAImageField.rawValue = eval(displayImage);
    break;
   
    case "3":
    fCounterA.value = "4";
    displayImage = imageName01 + integer03 + ".value.image.value";
    filmAImageField.rawValue = eval(displayImage);
    break;
   
    case "4":
    fCounterA.value = "1"; // loops back to the first image
    displayImage = imageName01 + integer04 + ".value.image.value";
    filmAImageField.rawValue = eval(displayImage);
    break;
}

3 Replies

Avatar

Level 10

Hi,

I would need to look at this in the cold light of day; however I think some of the issue may be when you are adding bits of info together, to form a reference. I suspect that you will need to resolve the node:

displayImage.rawValue = xfa.resolveNode("imageName01" + integer01 + ".value").image.value;

This happens in a few places. I think anytime you add an objects reference and a number, you will need to resolve these, so that Acrobat can reference an actual object or variable.

Later,

N.

Avatar

Level 3

Thanks for the response. I tried it out but now the button doesn't respond at all.

Again, the original code 'works' for a little while then stops.

And what happens when it stops is clicking does nothing and the images stop looping.

Since the code for displayImage 'works' is it the eval code that may be causing the issue?

filmAImageField.rawValue = eval(displayImage);

Avatar

Level 10

Hi,

It is a little difficult to say, without seeing an example of the form. 

I still think the main problem is that you are combining elements to form a reference to an object. Once you have combined the references together, you should resolveNode these into a full SOM.

If it is working, then stops, something basic is wrong. I don't think you need the eval() function. You could try something like this:

filmAImageField.rawValue = xfa.resolveNode("imageName01" + integer01 + ".value.image.value"); 

But I still think there are some mismatched statements in the script:

  • var whichSelect = filmTitle.$.rawValue;
  • var imageName = allImages[whichSelect][0];
  • I don't know what the combined reference "imageName013" is looking for. This is what you will get when you combine imageName01 with the integer.

Have you tried looking at the Javascript Console (Control+J) when previewing the form?

Hope that helps,

Niall