Skip navigation
Currently Being Moderated

Error using MouseEventHandler

Sep 17, 2007 9:31 AM

Hello,

There occurs an error when I register a MouseEventHandler with the following code(this code is executed always when the pdf-document is being opened):

function initialize()
{
var a3d = getAnnots3D(0)[0];
if ( a3d.activated )
{
context3D = a3d.context3D;

//Removes possible previous added MouseEventHandler
var handler = context3D.runtime.getEventHandler(0);
if(handler != null)
context3D.runtime.removeEventHandler(handler);

//Adds eventhandler
var meh = new context3D.MouseEventHandler();
meh.reportAllTargets = true;
meh.onMouseUp = true;
meh.onEvent = function(mouseEvent)
{
if(mouseEvent.isMouseUp)
{
try
{
var hits = mouseEvent.hits;
clickedNode = hits.shift().target;
var scene = context3D.scene;
var clickedMesh = scene.meshes.getByName(clickedNode.name);

if(vorigeNode != null)
{
var vorigeMesh = scene.meshes.getByName(vorigeNode.name);
vorigeMesh.renderMode = "solid";
}
vorigeNode = clickedNode;

clickedMesh.renderMode = "shaded illustration";
}
catch(err)
{
console.println(err);
}
}
}
context3D.runtime.addEventHandler(meh);
}

The error occurs at closing the pdf-file. The error-message is: "An unhandled win32 exeption occurred in Acrobat.exe[5068]. On another computer I also got an error like "The read or write operation on the memory failed.

Can someone help me and explain the cause and solution for this error?

Thanks in advance,

ewout
 
Replies
  • Currently Being Moderated
    1. ,
    Sep 17, 2007 1:04 PM   in reply to (ewoutnwn)
    ewout,
    I notice three things:

    1) you're missing a closing brace at line 7.
    2) It doesn't look like you're ever calling the function:
    initialize();

    3) If both of the above are just typo's, try adding a delay at the beginning of your script. It's probably that the 3D annot is not yet loaded when you're trying to access it.

    Good luck!
     
    |
    Mark as:
  • Currently Being Moderated
    4. ,
    Sep 20, 2007 11:50 AM   in reply to (ewoutnwn)
    ewout,
    I have a solution for you that works. But first, using you're approach I do indeed encounter crashes, though not every time. I worked with your script for quite a while, and also made more simplistic versions for MouseEventHandlers and RenderEventHandlers. Again, I get crashes, but it's intermittent and I haven't yet determined the exact cause.

    Here's the solution (simple code example below). The only needed change is that the function is now in a script attached to the 3D annot, and then that function is called from your page button. When I create eventHandlers, I typically create them in Javascripts attached to the 3D annot itself. This is the more efficient (in processing) method. If you would like a button on a page to create a handler(as in your example), put the function in a script attached to the 3D annot, and then call the function from the page. This works dependably with no errors at all. I have many many documents which use this approach successfully. The code below shows the 3D annot script at top and the page button script at bottom.

    //======= attach to 3D annot ========
    function initializeMEH()
    {
    myMEH = new MouseEventHandler();
    myMEH.onEvent = function(event)
    {
    console.println("=================");
    console.println("mouseX = " + event.mouseX );
    console.println("mouseY = " + event.mouseY );
    }
    runtime.addEventHandler(myMEH);
    }

    //======= attach to Page button =======
    var a3d = getAnnots3D(0)[0].context3D;
    a3d.initializeMEH();
     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)