Skip navigation
fredo5344
Currently Being Moderated

problem to execute an action after a delay, setTimeout in 3D PDF

Feb 29, 2012 6:47 AM

Hello,

I am new in the creation of 3D PDF and JavaScript, and I have a problem with the function SetTimeout.
I want to make a change texture on an object and after 3 seconds make another change texture on another object.
To do this, the function SetTimeout seemed the most effective but I can't get the expected result.

 

For information:
I declare two functions in my JavaScript file

 

function bouton_on(){

mat0 = scene.materials.getByName("bouton_on_inactive");

copyMaterialTexture(mat0.name,"bouton_on_active");

setTimeout("voyant_on()",1000);

}

function voyant_on(){

mat0 = scene.materials.getByName("voyant_inactive");

copyMaterialTexture(mat0.name,"voyant_active");

}

 

Dans le boutton de mon pdf , je fais bien appel à la fonction bouton_on()

getAnnots3D(0)[0].context3D.bouton_on();

 

And in button in my pdf, I do well bouton_on () function call

getAnnots3D(0)[0].context3D.bouton_on();

 

thank you for telling me what's wrong or help me to findanother solution.

 

Thanks

 

Bonjour,

Je suis novice dans la création de PDF 3D et Javascript, et je rencontre un problème avec la fonction SetTimeout.

Je souhaite effectuer un changement de texture sur un objet puis 3 secondes aprés effectuer un autre changement de texture sur un autre objet.

Pour ce faire , la fonction SetTimeout me semblait la plus efficace mais je n'arrive pas à obtenir le résultat attendu.

 

Pour information :

je déclare bien mes deux fonctions dans mon fichier Javascript

 

function bouton_on(){

mat0 = scene.materials.getByName("bouton_on_inactive");

copyMaterialTexture(mat0.name,"bouton_on_active");

setTimeout("voyant_on()",1000);

}

function voyant_on(){

mat0 = scene.materials.getByName("voyant_inactive");

copyMaterialTexture(mat0.name,"voyant_active");

}

 

Dans le boutton de mon pdf , je fais bien appel à la fonction bouton_on()

getAnnots3D(0)[0].context3D.bouton_on();

 

merci de me dire ce qui ne va pas ou de m'aiguiller vers une autre solution.

 

Cordialement.

 
Replies
  • Currently Being Moderated
    Feb 29, 2012 9:56 AM   in reply to fredo5344

    This is actually very complicated to do.

     

    "setTimeout" is not a global function in AcroJS - instead you have the app.setTimeOut() function. From within the 3D JS engine, you do not have direct access to the 'app' object, instead you must call it via

     

    host.app.setTimeOut("myFunction(variable)");

     

    The problem arises that myFunction() is called in the context of the host API (where "this" = "doc") - so you cannot directly use it to call a function within your 3D scene. It will instead involve two round-trips:

     

     

    function my3Dfunction(variable) { console.println(variable); }

     

    host.app.setTimeOut("getAnnots3D(pageNum)[0].context3D.my3Dfunction('h ello')",1000);

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 29, 2012 10:41 AM   in reply to Dave Merchant

    It might be clerarer to set up the function to be called in a document level script and then just use

     

    host.app.setTimeOut("myFunction('myVariable')");

     

    from the 3D object

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 29, 2012 11:50 AM   in reply to Joel_Geraci

    Either way, his called function is talking to the 3D scene so it has to construct a reference back into the 3D API. One day we might get an alias to these app-specific functions in runtime, but I'm not holding my breath!

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points