Copy link to clipboard
Copied
I am a researcher. I am trying to develop a labeling tool in acrobat with javascript. The tool should be able to create a bound box, the four sides of which can be moved by a mouse.
The code works fine during the developing process, until I move the calling code into the callback function of a menu item. The questionable code is this line:
Copy link to clipboard
Copied
What's the canAccessFieldTree method? Is it something you defined? If so, where is it placed, and how is it associated with the doc variable (which I assume points to a Doc object)?
Copy link to clipboard
Copied
I didn't defined canAccessFieldTree. I guess it is defined by acrobat.
Copy link to clipboard
Copied
I didn't defined canAccessFieldTree. I guess it is defined by acrobat.
By @Lin29507547y6ua
That makes sense. The other part of the error message is "Missing Mesh Restriction". I'm pretty sure this message is related to the 3D JavaScript model. Quite often, Acrobat reports wrong errors. I've seen the 3D model errors get reported for exceptions on document model functions. Not very helpful.
Copy link to clipboard
Copied
So, you're asking us about an internal problem with a complex system of your own design? You've created you're own set of objects and terminalogy. How are we supposed to know what you are talking about?
Given that I don't know anything about your code I can't say anything specific, but there are some general Acrobat scripting technique issues that may help you.
The error shown isn't from code in the menu, mouseup action, or a folder level script. It's from code run in the console. It's reporting that an object member named "canAccessFieldTree" is not defined. I'm assuming that "Doc" is a variable representing the a document object. It's important that you've run code in the console that defines functions and variables because of context, which I'll explain below.
First, a helpful practice is to put any code that is more than one very simple line into a fucntion. For example the code executed by the menu item. It's also very helpful, if the code is debuged, to place these functions in a folder level script.
Next, the Acrobat scripting environment is context sensitive. So it's important to understand and control the context of your code. For exmaple, it may be that a particular operation requires privilege, in that case the code for that operation needs to be place in a privileged context, such as a folder level trusted function. Context also controls the meaning of "this". When you executed code in the console window it was in the context of the current document object, so "this" was the documement object. It also means that any functions or variables defined by that code only exists for that document object. If you changed documents, the menu code probably wouldn't work at all.
The context is different for code run in a folder level script, and code run from a menu item or toolbar. This may be why your document level variable isn't being set properly. For a menu item script, the current document is in the "event.target" property. It is also in the undocumented "app.doc" property. The context can also change when one fucntion calls another. So any necessary data that may be context sensitive needs to be explicitly passed it the called function.
Another possible issue is your box. It appears to be a set of buttons and possibly a rectangle annotation. If this is true, then you'll need to handle the coordinates spaces properly or the system will break down with a page that is rotated and/or has different media and crop boxes.
In fact, it all seem overly complex. A simpler solution is to use a single button as the box. Start a timer on mouse down that runs a function to track the mouse position and use it to move the button. On mouseup, kill the timer.
Copy link to clipboard
Copied
Thanks for your immediate and sincere reply. I found my bug. I made the bug by moving the code from the document level to the folder level. I had thought the bug is because of the code I newly wrote. I debugged it in the wrong direction. Thanks for pulling me back on the right track. Thanks.